Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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
Node.js 要在数组中查找或更新的MongoDB查询不';我不能正常工作_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 要在数组中查找或更新的MongoDB查询不';我不能正常工作

Node.js 要在数组中查找或更新的MongoDB查询不';我不能正常工作,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我正在做一个新项目,第一次用下面的模式收集了大量的消息- mongoose.model('Messages', { owner: { type: Schema.Types.ObjectId, ref: 'User' }, messages: [{ with: { type: Schema.Types.ObjectId, ref: 'User' }, from: {id: { type: Schema.Types.ObjectId, ref: 'U

我正在做一个新项目,第一次用下面的模式收集了大量的消息-

 mongoose.model('Messages', {
    owner: { type: Schema.Types.ObjectId, ref: 'User' },
    messages: [{
        with: { type: Schema.Types.ObjectId, ref: 'User' },
        from: {id: { type: Schema.Types.ObjectId, ref: 'User' }, user: String},
        to: [{id: { type: Schema.Types.ObjectId, ref: 'User' }, user: String}],
        sent: {type: Date, default: Date.now},
        message: String,
        seen: {type: Boolean, default: false},
        stared: {type: Boolean, default: false}
    }]
})
我使用的大多数查询都是查找用户(所有者)和其他用户(messages.with)的消息,其中发送日期(messages.sent)大于日期-

Messages.findOne({owner: owner.id, "messages.with": user.id, messages.sent: {$gt: mydate}},{messages: 1, owner: 1}, function (err, doc){}..)
我应该得到文件,只有当有更大的消息(之后)的日期,我输入,否则得不到任何东西。 例如,我在查询中使用的日期设置为新日期('2015-12-04T03:39:23.126Z'),因此我认为日期格式没有任何问题 因此,随着更新-

Messages.update({owner: owner.id, "messages.with": user.id}, {$set:{"messages.$.seen": true}}, function(err, numEffected) {})
就是不管用。
目前,我使用另一个函数检查数据,但这是不必要的。
请帮我弄清楚

感谢更新不起作用,我在使用findOneAndUpdate(条件、更新、回调)时遇到了这个问题。然后它对我起作用了

我也试过这个,还是同样的问题。无论如何谢谢你