Using cursor.batchSize() with db.collection.find()
I am trying to use cursor.batchSize() with db.collection.find()
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://127.0.0.1';
const dbName = 'users'
MongoClient.connect( url, ( err, client) => {
var cursor = client.db(dbName).collection('exampleCOllection').find().batchSize(2);
cursor.toArray()
.then( (value) => {
console.log(value)
})
.catch( (error) => {
console.log(error)
})
})
but it outputs all the results instead of the given batchSize i.e. '2'. I tried using {batchSize:2} after db.collection.find() but it didn't made any difference. Can anybody have a look and suggest anything?