MongoDB能同时插入或更新两个或多个collection吗?
phpcn_u1582
phpcn_u1582 2017-05-02 09:19:27
0
2
635
这是collection a:
武功:["一阳指","九阴真经","辟邪剑谱"]

collection b:
主要技能: "一阳指",
杀伤力:"90"

这样我前台传来数据{技能:"龙爪手",
                   杀伤力:"80"}
                
这个数据既要插入collecttion b
也要把技能:就是龙爪手更新到collection a的"武功"里
类似就b是a的子表

有什么能让他们关联到一起,一次插入而不用一个表一个表的插入。
因为有的字段可能关联多个collection。更新同理
phpcn_u1582
phpcn_u1582

reply all(2)
習慣沉默

Sorry, original poster, I read it wrong. Mongo does not have such a thing as multi-table transactions. You’d better make it in the form of sub-objects within the table

Python has bulk_write, and most other languages ​​also have it
reqs=[pymongo.DeleteMany (the parameters are actually the same as the delete function), pymongo.UpdateOne (the parameters are actually the same as update_one), pymongo.Insert (same as above)]

database.conns.bulk_write(reqs)

仅有的幸福

It’s best not to divide the tables. . Mongo’s lock library level

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