mongodb用python插入2个集合相同_id
高洛峰
高洛峰 2017-04-18 09:17:26
0
2
331

就是有2个集合,
然后2个集合同时插入数据。
希望数据的_id是一样的。我插入的时候老是相差1。
想问怎么实现,谢谢了

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
PHPzhong

Before inserting data, use _id = ObjectId() to generate the id and put it into two dicts, then perform the save action

阿神

The writing below shell is

var id = new ObjectId();
db.coll_1.insert({
    _id: id,
    ...    // 其他字段
})
db.coll_2.insert({
    _id: id,
    ...    // 其他字段
})

In short, just make a new oneObjectId by yourself.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template