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

MongoDB数据批量更新的问题。

  •  
  •   shin · Oct 20, 2013 · 10870 views
    This topic created in 4591 days ago, the information mentioned may be changed or developed.


    单条数据如上所示,我需要将所有的<code>P:数据值</code>更改为<code>P:[数据值]</code>,整个文档所有数据都需要改。
    3 replies    1970-01-01 08:00:00 +08:00
    gamexg
        1
    gamexg  
       Oct 21, 2013
    加个版本号,然后使用时在处理。
    barrysfinalhome
        2
    barrysfinalhome  
       Oct 21, 2013
    全部更新为某一个数值?
    ijse
        3
    ijse  
       Oct 21, 2013
    db.CollectionName.find().forEach(function(doc) {
    doc.T.forEach(function(x) {
    x.P = [ x.P ];
    });
    db.CollectionName.save(doc);
    });

    在mongo里执行试下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:52 · PVG 04:52 · LAX 13:52 · JFK 16:52
    ♥ Do have faith in what you're doing.