문제

I want to use Mongoose to find a object by _id then then the 10 preceding objects. I have found how to sort to order by date and the find function to find a specific object by id and the limit function to limit the results to 10, I just have not figured out how to find a specific object and the 9 objects that come after it.

도움이 되었습니까?

해결책

Mongoose is built on MongoDB, and the query syntax is essentially identical between the two. The advanced queries page has a section on inequality matching.

I haven't tested this, but since the MongoDB ID is a monotonically-increasing (but pseudo-random) integer, it should be possible to:

db.myCollection.find( { _id : { $gte : myIdVal } } ).limit(10);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top