获取最近 30 分钟内更新的 mongo 文档 [英] fetch mongo documents updated within last 30 minutes
本文介绍了获取最近 30 分钟内更新的 mongo 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取最近 30 分钟内更新的文档
I want to fetch documents updated within last 30 minutes
每个文档都有Date类型的updateAt字段
each document has updatedAt field of Date type
我正在做以下事情:
Model.find({
updatedAt : { $gte : new Date(Date.now() - (30 * 60000)) } },
function(err, docs){
console.log(err); //null
console.log(docs); //empty array []
});
但实际上我有文档在过去 30 分钟内通过从猫鼬控制台查看更新了值.
But i actually i have documents which have updatedAt value within the last 30 minutes by viewing from the mongoose console.
我做错了什么?
推荐答案
试试这个:
Model.find({
updatedAt : { $gte : new Date(ISODate().getTime() - 1000 * 60 * 30) } },
function(err, docs){
console.log(err); //null
console.log(docs); //empty array []
});
这篇关于获取最近 30 分钟内更新的 mongo 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文