0
db.collection('users', function(err, users)
{
    if (!err)
    {
        users.update({company:cursor[i].name}, {$set:{active:false}}, function() {});
    }
});

cursor[i].name有一个字符串值,当我显示console.log()它时它显示得很好。

文档未更新。我在 MongoHQ 中使用远程数据库并使用本机 mongodb 驱动程序运行 Node.js 服务器。如果我在连接到同一个数据库时在 shell 上运行查询,它工作正常。

编辑:我使用了一个 int 而不是false它工作得很好。我可以在 mongodb 中插入布尔值吗?如果是这样,怎么做?

4

1 回答 1

1

用 1.2.9 的驱动测试了它,它工作正常。

exports.shouldUpdateCorrectlyWithBoolean = function (test) {
  var db = new Db(MONGODB, new Server("127.0.0.1", 27017,
    {auto_reconnect: false, poolSize: 1}), {w: 1, native_parser: false});

  db.open(function (err, db) {
    db.collection('update_with_boolean').insert({company: 'a'}, function(err, result) {
      test.equal(null, err);

      db.collection('update_with_boolean').update({company: 'a'}, {$set: {active:false}}, function(err, result) {
        test.equal(null, err);
        test.equal(1, result);

        db.collection('update_with_boolean').findOne(function(err, item) {
          test.equal(null, err);
          test.equal(false, item.active);

          db.close();
          test.done();
        });
      });
    })
  });
}
于 2013-01-15T12:25:48.460 回答