簡體   English   中英

MongoDB文檔子數組分頁

[英]MongoDb document sub array pagination

我正在將帖子評論存儲在帖子中,現在面臨的問題是我不能對文檔數組使用skip跳轉限制,因為用戶可以根據需要發布任意數量的評論,因此數組很大,所以我想對評論進行分頁。

有沒有辦法做到這一點?

每個通話只能檢索10條評論嗎?

謝謝!

{
  id:0,
  ref:0,
  type: 'image',
  date: null,
  title: 'this is my title',
  comments:[
      {
        user : 'myUser',
        text : 'text'
      },
      {
        user : 'myUser2',
        text : 'text2'
      }
}

找到解決方案:在投影中執行:

projection(“ {comments:{$ slice:[#,#]}}”,開始,大小)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM