Arrays mongoDB数组分页

Arrays mongoDB数组分页,arrays,mongodb,pagination,Arrays,Mongodb,Pagination,我有一个注释集合,其中注释文本位于带有元数据的数组中。我喜欢注释文本数组中的分页。分页应该允许我获得“上一个5”或“下一个5”。在性能良好的mongoDB中实现这一点的最佳方法是什么 { "_id" : ObjectId( "502c706ac2e6777781a593f6" ), "commentType":"loc", "commentList" : [ { "commentText" : "HelloComment", "commentTS" : Dat

我有一个注释集合,其中注释文本位于带有元数据的数组中。我喜欢注释文本数组中的分页。分页应该允许我获得“上一个5”或“下一个5”。在性能良好的mongoDB中实现这一点的最佳方法是什么

   { "_id" : ObjectId( "502c706ac2e6777781a593f6" ),
      "commentType":"loc",
      "commentList" : [ 
{ "commentText" : "HelloComment",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "2222222",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "3333333",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "44444444",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "5555555",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "6666666",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
    { "commentText" : "777777",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
    { "commentText" : "888888",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
    { "commentText" : "6666666",
  "commentTS" : Date( 1345165636344 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fd182d92b2a87f780c6bbe8" ) } }, 
{ "commentText" : "999999",
  "commentTS" : Date( 1345165668809 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fdeb271de26fd298262bb84" ) } }, 
{ "commentText" : "HelloComment",
  "commentTS" : Date( 1345749858601 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fdeb271de26fd298262bb84" ) } }, 
{ "commentText" : "NewTestforcomments",
  "commentTS" : Date( 1345750020526 ),
  "commentLoc" : { "commentlat" : 0,
    "commentlong" : 0 },
  "userInfo" : { "$ref" : "userProfile",
    "$id" : ObjectId( "4fdeb271de26fd298262bb84" ) } } ],
   } } 

谢谢您的帮助。

您可以使用
$slice
完成此操作:

还有一个

因此,
findOne
,再加上
$slice
,可能是一条可行之路


如果没有关于您使用的语言的更多信息,我想这是我能做的最深的了。

您可以使用
$slice

还有一个

因此,
findOne
,再加上
$slice
,可能是一条可行之路


如果没有更多关于您使用的语言的信息,我想这是我能做的最深的了。

到MongoDB的链接已断开。使用此信息获取有关投影中$slice的信息:到MongoDB的链接已断开。有关投影中的$slice的信息,请使用此选项: