gpt4 book ai didi

javascript - MeteorJS 和 MongoDB : How to get next 10 entries

转载 作者:行者123 更新时间:2023-12-03 11:27:23 33 4
gpt4 key购买 nike

我有一个这样的数据库:

{
"_id" : "xFZtChfKTf3GLxFEg",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "Kissing Prank - How to Kiss ANY Girl in 10 SECONDS - Kissing Strangers/Funny Videos/Best Pranks 2014",
"v_id" : "Fa1agPyuRRM",
"views" : 0
},
{
"_id" : "RB2uwCfsjujFwFpZe",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "Dropping Guns in the Hood (PRANKS GONE WRONG) - Pranks in the Hood - Funny Videos - Best Pranks 2014",
"v_id" : "K1SksoAHIa0",
"views" : 0
},
{
"_id" : "3CvrFtYo4wWE5Coj7",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "TOP Pranks 2014 - Pranks in the Hood - Pranks Gone Wrong - Funny Pranks 2014 - PRANK COMPILATION",
"v_id" : "oEgXOhxXvsc",
"views" : 0
},
{
"_id" : "doiA7EPkwCe5meyJ7",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "Top 5 Pranks of 2014",
"v_id" : "A9w72vSuPAQ",
"views" : 0
},
{
"_id" : "8oK2JxqJfEkzceWHB",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "Friday The 13th Scare Prank",
"v_id" : "6m4isWlUlRE",
"views" : 0
},
{
"_id" : "5NwM2fbnifKejgSct",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "7 SUPER EASY PRANKS - HOW TO PRANK",
"v_id" : "RckNziU2JEk",
"views" : 0
},
{
"_id" : "x5QqJu2e54kjFpfkz",
"category" : "pranks",
"date" :new Date(),
"rate" : {
"up" : 0,
"down" : 0
},
"user" : "User_1",
"vTitle" : "Orphanage Robbery Prank!!",
"v_id" : "dBfVwjRuwxk",
"views" : 0
},

如果我有“_id”:“3CvrFtYo4wWE5Coj7”,如何获取从“_id”:“3CvrFtYo4wWE5Coj7”开始的日期的下 10 个条目并预览 10 个条目?

假设我在“_id”之前有 500 个条目:“3CvrFtYo4wWE5Coj7”,在之后有 500 个条目。

编辑:我所知道的是来自iron:router参数“id = this.params._id”的条目ID,然后我必须找到该条目并获取“该条目+下一个10”或“该条目+上一个10”。

最佳答案

当你得到一个随机文档时,为什么不能查看它的日期,然后在 MongoDB 中查询接下来 10 个较旧/较新的文档(取决于你想要的方向)?

Collection.find({$and[{date:{$gte:{mydocument.date}}},{_id:{$ne:mydocument._id}}]},{sort:{date:1}}).limit(10)

这意味着您订阅了集合中的所有文档,考虑到集合的大小,这当然可能不是最好的做法。相反,您可能想更改订阅/发布以仅发布您真正想要的文档。

关于javascript - MeteorJS 和 MongoDB : How to get next 10 entries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863799/

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