4
MongoDB的集合 “测试” 包含一条记录:猫鼬ODM:NumberInt没有定义
{ "_id" : ObjectId("56f53cded3095c203024a884"), status : 0 }
我是通过连接Node.js的(猫鼬驱动程序)蒙戈。定义架构此集合:
"Test" : {
status : { type : Number, default : 0 }
}
田“状态”是一个二进制符号,必须是只存储0或1的数值。我想改变这个标志更新查询:
test.update({ 'status' : 0 }, { $bit : { 'status' : { xor : NumberInt(1) } } }, function(err, result) {
if(err) {
console.log('err');
}
});
猫鼬未发现NumberInt()
功能:
ReferenceError: NumberInt is not defined
当我把简单的数字“1”没有功能NumberInt()
,我不会有任何变化或错误。
在查询完美运行的MongoDB shell中。我如何在Mongoose驱动程序中使用NumberInt()
?它有另一个名字吗?
谢谢。我声明var Int32 = require('mongoose-int32');并执行查询:test.update({'status':0},{$ bit:{'status':{xor:new Int32(1)}}} ...);但字段“状态”不会再次改变(可能是我做错了什么? –
您是否尝试过将'status'类型''Int32'而不是'Number'? –
对不起,这工作正常。谢谢! –