![](/img/trans.png)
[英]How to get the last inserted _id from MongoDB using node express
[英]How to fetch a document from MongoDB inserted only within last few minutes?
我正在使用以下查詢來獲取最新文檔。
const user = await Conversation.find({ isBot: false, to: from.slice(9), queryType: "template_preview" }).sort({ sentTime: -1 }).limit(1);
但問題是這也可以獲取很久以前插入的舊文檔。 但是對於我的用例,我希望在幾分鍾前插入文檔,比如 5 分鍾。 對此的確切查詢應該是什么。
試試這個:
const user = await Conversation.find({
isBot:false,
sendTime:{
$gte: timestamp of -5 min,
$lte: timestamp (now)
},
queryType: "template_preview"
}).sort({ sentTime: -1 });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.