2

I need to use limit and skip to get some record from mongo.

I am using MongoJS with NodeJS but below given is not working.

Below is an example:

db.users.find(function(err,doc{
  console.log(doc);
})).skip(2).limit(2);

also I have tried something like:

db.users.find({ skip:0, limit: 5 }, function(err, results) { 
  console.log(results);
});

I am new to JS/NodeJS/MongoJS ,Please let me know how can I use above code correctly .

blackbishop
  • 30,945
  • 11
  • 55
  • 76
Vivek Panday
  • 1,426
  • 2
  • 16
  • 34

1 Answers1

8

I tried and found - The correct code is -

db.users.find({}).limit(2).skip(0, function(err, docs) { console.log(docs); });

Might It can help others. If any other suggestions are there please share.

Vivek Panday
  • 1,426
  • 2
  • 16
  • 34