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?
Biplab Malakar
Senior Software Engineer, JavaScript Developer, MEAN Developer, Node.js Developer, MERN Developer, Hybrid Mobile App Developer and ML Develo
Read this doc written mongoDB about batchSize() docs.mongodb.com/manual/reference/method/cursor.b…