db.comments.find({"_id" : {"$gte": ObjectId("6225f932a7bce76715a9f3bd"), "$lt":ObjectId("6225f932a7bce76715a9f3bd")}}).sort({"created_datetime":1}).limit(10).pretty()
I am using this query which should give me the current “6225f932a7bce76715a9f3bd” doc, 4 docs inserted before this and 5 docs inserted after this. But currently when i run this query, i get null result. Where am i going wrong ??
Advertisement
Answer
I had no other option but to seperate my queries in order to achieve my expectation.
JavaScript
x
9
1
query = request.args.to_dict()
2
find_query = {}
3
find_query["_id"] = {"$lt": ObjectId(query["comment_id"])}
4
previous_comments = list(db.comments.find(find_query))
5
find_query["_id"] = {"$gte": ObjectId(query["comment_id"])}
6
next_comments = list(db.comments.find(find_query))
7
previous_comments.extend(next_comments)
8
return {"comments":previous_comments}
9