推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
aoscici2000
V2EX  ›  MongoDB

pymongo 更新某字段直接增加数据怎么操作?

  •  
  •   aoscici2000 · Mar 19, 2019 · 4461 views
    This topic created in 2611 days ago, the information mentioned may be changed or developed.

    例如某条数据结构如下 {"key_1": "XXX", "key_2": [{...}, {...}]}

    需要在 key_2 中的 [] 中增加一条 {...}, 现在只会先找出这条数据, 拿出 key_2, 添加, 然后再更新, 能直接通过 update 一步操作完吗 ?

    3 replies    2019-03-20 10:09:31 +08:00
    Trim21
        1
    Trim21  
       Mar 19, 2019 via iPhone   ❤️ 1
    $push
    aoscici2000
        2
    aoscici2000  
    OP
       Mar 19, 2019
    @Trim21 感谢感谢
    TrickWu
        3
    TrickWu  
       Mar 20, 2019
    去重的话还可以用 $addToSet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3368 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    ♥ Do have faith in what you're doing.