The new:true option returns me the old value in Mo

2019-09-01 15:53发布

问题:

I'm using the following code in MongoDB v2.2 NodeJS 0.8 MongoSkin 0.5 Framework:

var db = mongo.db(admin+"@127.0.0.1:27017/database",{safe:true});
db.collection('collection').findAndModify({'code':code,'email':email},[],
    {
        $push:
        {
            'code.pub':newPub,
        }
    },{new:true},
    function(err, result)

The new true option returns me the old value in MongoDB. Why is this happening? What is wrong?

回答1:

set {w: 1} or, {safe: true} which is deprecated.



回答2:

in your query you search for: "{'code':code,..." and in the update you say "$push: {code.pub...

If your "code" field contains an object (sub-document) - your query will not find anything and the update will fail

Could you please post the complete statement (with the content of the variables) and an example of the document being updated?

Cheers

Ronald