search

Home  >  Q&A  >  body text

MongoDB能同时插入或更新两个或多个collection吗?

这是collection a:
武功:["一阳指","九阴真经","辟邪剑谱"]

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

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

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

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-02 09:21:27

    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)

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:21:27

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

    reply
    0
  • Cancelreply