找到你要的答案

Q:MongoDB Update returns true, but not reflected in DB

Q:MongoDB更新返回true,但没有反映在DB

I'm sending an update to mongo (via a javascript function). I am simply adding a new boolean field to an existing document which has an existing field of emailAddress.

the result comes back as:

{"ok":true,"n":1,"updatedExisting":true}

However, when I check the db directly, it has not actually been updated.

This is the actual code. Anyone know why this might not be working? it is as though the update hasn't been committed or is in some sort of cache.

var updateEmail = function (address, flagVal, dbName, callback) {

  var newVal = (flagVal === 'true');  
  var newField = {"Bounced" : newVal };
  //collection is global variable in file
  collection.update({"emailAddress":address}, 
                                {$set : newField }, 
                                {upsert:false, multi:false, writeConcern: {w:"marjority"}},
                                function (err, result) { 
    if (err) {
      callback(err);
    }
    console.log(JSON.stringify(result));
    callback(null);
  });
  callback(null);

}

我发送一个更新Mongo(通过一个JavaScript函数)。我只是有一个现有的领域将现有的文档中添加一个新的布尔字段。

结果回来:

{“OK”:真的,“N”:1,“updatedexisting”:true}

但是,当我直接检查DB时,它实际上并没有被更新。

这是实际代码。有人知道为什么这不起作用吗?好像更新没有被提交或者是在某种缓存中。

var updateEmail = function (address, flagVal, dbName, callback) {

  var newVal = (flagVal === 'true');  
  var newField = {"Bounced" : newVal };
  //collection is global variable in file
  collection.update({"emailAddress":address}, 
                                {$set : newField }, 
                                {upsert:false, multi:false, writeConcern: {w:"marjority"}},
                                function (err, result) { 
    if (err) {
      callback(err);
    }
    console.log(JSON.stringify(result));
    callback(null);
  });
  callback(null);

}
javascript  mongodb