Node.js mongodb Third parameter to `find()` must be a callback or undefined

295 views
Skip to first unread message

mc

unread,
Aug 24, 2018, 2:39:31 PM8/24/18
to mongodb-user
Hello,
I recently updated Node.js mongodb module to version 3.1.3.
I have this call in my code:
db.collection(collectionName).find(query, projection, options).toArray(cb);

This call succeeds but it also prints warnings to console:
Third parameter to `find()` must be a callback or undefined

According to doc files for this call:
https://mongodb.github.io/node-mongodb-native/markdown-docs/queries.html

Syntax seems to match (query, fields = projection, options and callback = cb):
collection.find(query[[[, fields], options], callback]);

Does anyone know what is mongodb code complaining about?
Thanks a lot,

M

Kevin Adistambha

unread,
Aug 26, 2018, 11:34:55 PM8/26/18
to mongodb-user

Hi,

db.collection(collectionName).find(query, projection, options).toArray(cb);

Node driver version 3.1 and newer have a different method signature for find(). The documentation page you linked to is for node driver version 1.4.9, which is not up to date anymore. Please find the current find() documentation in http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#find. Some relevant code examples for the current driver version can be found under CRUD operations.

I believe the warning was due to the find(query, projection, options) syntax in your code. Note that in node driver 3.1, projection is now located under options instead of its own separate parameter.

If you’re still having issues with this, please post the relevant part of the code that’s giving you the error.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages