Unable to execute batchSize function in mongodb app services functions

Hi Team ,

I have millions of records in collection . I have created a scheduled trigger which will run every minute . On trigger function i am retrieving 1000 records then updating it . Below is the query i have used

const filteredData = await auditEvents.find({ ID: { $exists: true }, DATA: { $exists: true } }).limit(1000).toArray();

However in profiler i saw it is returning only 101 records which is default batch size . so i updated the query as below:

const filteredData = await auditEvents.find({ ID: { $exists: true }, DATA: { $exists: true } }).limit(1000).batchSize(1000).toArray();

But it is giving me error : Error occurred while executing : ‘batchSize’ is not a function

Same query works locally (vscode) . Is there any option to enable batch size in mongodb atlas ?

Could you please help here .

Hi @Yogini_Manikkule - Welcome to the community.

As per the Return Value section of the MongoDB API Reference documentation:

The collection.find() method returns a cursor object that points to any documents that match the specified query.

You can manipulate and access documents in the query result set with the cursor methods mentioned in the documentation linked above but it does not yet have batchSize() as a method to work off. However, in saying so, can you detail the use for batchSize in this scenario? You may wish to create a feedback request for this as well in which others can vote for.

Could it be that the full query itself is returning 101 documents that match? i.e. There are no more than 101 documents that match.

Regards,
Jason

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.