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

前端 未结 4 1676
误落风尘
误落风尘 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:31

    1. Your are using exists in the wrong way.
      Syntax: { field: { $exists: } }

    2. You use of $where is also incorrect
      Use the $where operator to pass either a string containing a JavaScript expression or a full JavaScript function to the query system

      db.myCollection.find( { $where: "this.credits == this.debits" } ); db.myCollection.find( { $where: "obj.credits == obj.debits" } );

      db.myCollection.find( { $where: function() { return (this.credits == this.debits) } } );

      db.myCollection.find( { $where: function() { return obj.credits == obj.debits; } } );

    I think you should use Map-Reduce for what you are trying to do.

提交回复
热议问题