gpt4 book ai didi

javascript - 在 mongo 中查找上周创建的对象

转载 作者:IT老高 更新时间:2023-10-28 13:25:47 25 4
gpt4 key购买 nike

我有一个集合,其中有一个名为 timestamp 的字段,其中包含日期对象。我有这个查询:

db.articles.find({
timestamp:{
'$lte':new Date(),
'$gte': //Something to get the last week's date
}
})

另外,如果可能的话,我可以按此文档中数组的长度对这些返回的文档进行排序吗?这是架构:

section: String,
title: String,
abstract: String,
url: String,
image: {
url: String,
caption: String
},
votes:{
up: [ObjectID],
down: [ObjectID]
},
comments:[ObjectID],
timestamp: Date

我想按 votes.upvotes.down 的差异大小对返回的对象进行排序。现在我在 Javascript 中对返回的对象进行排序,这实际上返回了数据。

最佳答案

似乎解决方案应该是这样的

db.articles.find({
timestamp: {
$gte: new Date(new Date() - 7 * 60 * 60 * 24 * 1000)
}
});

关于javascript - 在 mongo 中查找上周创建的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com