I am getting frustrated with these two methods. According to MongoDB documentation I can find limit sort and skip something like this:
db.collection('demo_products').find({'groupid':{$exists: false}}).sort({'_id': 1}).limit(5).toArray()
But when I try it I get this error:
TypeError: db.collection(...).find(...).sort is not a function
I tried something different:
db.collection('demo_products').find({'groupid':{$exists: false}}, {limit: 5}).toArray()
and this worked well until I wanted to sort and skip:
db.collection('demo_products').find({'groupid':{$exists: false}}, {sort: {'_id': 1}}, {skip: 1}, {limit: 5}).toArray()
It completely disregarded sort and skip operations. I tried aggregation as well, but I couldn't find $exists operator in aggregation.
I find .find()
method more easier to use for me, but I can't figure out how to use sort and skip correctly.
I find the documentation quite misleading since it's suppose to work, but it throws the error all the time I follow it.