V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
shin
V2EX  ›  MongoDB

MongoDB数据批量更新的问题。

  •  
  •   shin · 2013-10-20 20:59:37 +08:00 · 9815 次点击
    这是一个创建于 3839 天前的主题,其中的信息可能已经有所发展或是发生改变。


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

    在mongo里执行试下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1002 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:12 · PVG 04:12 · LAX 13:12 · JFK 16:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.