【发布时间】:2016-03-12 03:53:25
【问题描述】:
在我的 mongo 中有文档
{
"_id": ObjectId("56658b4b9f41447c29f8d78e"),
"hostname": "VSX-01",
"time": "15:03:11",
"day": "7",
"con": [
"100000",
"4994",
"9",
"19904",
"7772",
"13323",
"245",
"14",
"221"
],
"cpu": [
"0",
"0",
"0",
"102",
"20",
"0",
"0",
"0",
"0"
],
"__v": 0
}
并且喜欢使用下面的猫鼬查询来查找和更新它,没有任何反应,打印
var newMessage = new Message(conmessage);
console.log(conmessage); /* Prints { hostname: 'VSX-01',
cpu: [ 0, 0, 0, '102', '20', 0, 0, 0, 0 ],
con: [ '100000', '4994', '9', '19904', '7772', '13323', '245', '14', '221' ],
time: '15:03:11',
day: '7' }*/
newMessage.find({'time': conmessage.time}, //findOneAndUpdate
function(err, message) {
if (err) throw err;
console.log(message);
})
我的架构 var messageSchema = new Schema({hostname: String, cpu: [String], con: [String], time: String, day: String});
【问题讨论】:
-
你想创建带有 conmessage 的 newMessage 然后想稍后再找到那个 newMessage 吗?或者有什么请解释一下。
-
我在变量“conmessage”中收到新消息,并想查找具有相同“时间”的消息是否已经在数据库中。我正在使用“findOneAndUpdate”,但暂时将其简化为“find”。 newMessage.save 工作正常...只是没有任何 newMessage.find...