Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用节点';s mongodb包_Javascript_Arrays_Node.js_Mongodb_Push - Fatal编程技术网

Javascript 使用节点';s mongodb包

Javascript 使用节点';s mongodb包,javascript,arrays,node.js,mongodb,push,Javascript,Arrays,Node.js,Mongodb,Push,我试图更新一个文档,将一个对象添加到名为subscription\u history的数组字段中 对象是这样的: { memberId: int, subscription_history: array } 守则: db.collection('users').update( { memberId: data.memberid }, { $push: { subscription_history: {

我试图更新一个文档,将一个对象添加到名为subscription\u history的数组字段中

对象是这样的:

{
   memberId: int,
   subscription_history: array
}
守则:

db.collection('users').update(

    {
         memberId: data.memberid
    }, {
         $push: {
             subscription_history: {
                 joined: new Date(data.joined*1000),
                 expires: new Date(data.expires*1000)
             }
         }
    }, {
         //upsert: true,
         multi: true
    }, function (err, updated) {
          if (err) {
              console.log(err)
          }
    });
});

查询在mongodb客户端“robomongo”中运行,但在node.js客户端包中运行不正常,我不知道为什么。有什么想法吗?

请发布您的节点代码。不看你在做什么,就不可能提出任何建议。你是什么意思?代码就在那里,您正在显示
memberId
是一个
int
。很可能
data.memberId
是一个“字符串”。使用
{“memberId”:parseInt(data.memberId)}
强制转换为正确的类型。同样,其他
数据
元素也可能是字符串,同样如此。当从
req.params
req.body
等源获取
数据时,这是一个常见错误,其中此类请求的内容几乎总是一个“字符串”。如果您不确定,那么
console.log(data)
并将该细节添加到您的问题中。谢谢,我会尝试的that@BlakesSeven是的,就是这样。非常感谢你的帮助