[DOCS-1744] Use Cases - Storing Comments Created: 25/Jul/13  Updated: 24/Feb/16  Resolved: 18/Mar/15

Status: Closed
Project: Documentation
Component/s: ecosystem
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Matt Campbell Assignee: Andrew Aldridge
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 8 years, 47 weeks, 5 days ago

 Description   

The code example under the heading view paginated comments on http://docs.mongodb.org/manual/use-cases/storing-comments/ doesn't seem to work.

The code seems to indicate that the find will be run on each iteration of the cursor and update the skip and limit variables. However, this doesn't appear to be the case. The original skip and limit values passed into the find are used on each document matched.



 Comments   
Comment by Githook User [ 20/Mar/15 ]

Author:

{u'username': u'i80and', u'name': u'Andrew Aldridge', u'email': u'i80and@foxquill.com'}

Message: DOCS-1744: Fix comment pagination example, s/page/bucket
Branch: master
https://github.com/mongodb/docs-ecosystem/commit/8d7556274deb1c9b5613248694d4e850efde7473

Comment by Matt Campbell [ 25/Jul/13 ]

Here is a solution that works:

def find_comments(discussion_id, skip, limit):
result = []
pages = db.test.find(

{ 'discussion_id': discussion_id }

,

{ 'page': 1 }

)
pages = pages.sort('page')

for page in pages:
page_query = db.test.find_one(

{ 'discussion_id': discussion_id, 'page': page['page'] }

,
{ 'count': 1, 'comments':

{ '$slice': [ skip, limit ] }

}
)
result += page_query['comments']
skip = max(0, skip - page_query['count'])
limit -= len(page_query['comments'])
if limit == 0: break
return result

You perform a find call for each page. If it can be done the way outlined at the above mention page it would be good to know what environment / setup it works under.

Generated at Thu Feb 08 07:41:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.