MongoDB update. Trying to set one field from a property of another

前端 未结 4 1757
误落风尘
误落风尘 2021-02-05 20:08

What I\'m trying to do is pretty straightforward, but I can\'t find out how to give one field the value of another.

I simply want to update one field with the character

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 20:35

    As far I know the easiest way is the read and write aproach:

    //At first, get/prepare your new value:
    var d= db.yourColl.fetchOne({....});
    d.field1== d.field2.length;
    
    // then update with your new value
    db.yourColl.save(d);
    

提交回复
热议问题