Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js non-blocking mongodb calls

I am relatively new to Node.js and working on a project with MongoDB as database. Some of the MongoDB queries are expensive. For example, I have a collection with millions of records and based on the search criteria the find query can take 1-2 seconds.

Does the call to MongoDB (using Mongoose driver) block Node.js from processing other requests until MongoDB returns results?

Also, are there any tools to identify potential lines of code that are of a blocking nature?

Thank you.

like image 876
LAX_DEV Avatar asked Nov 27 '25 09:11

LAX_DEV


1 Answers

@user949300 provided correct answer.

In general, if they have a callback in the function signature they ar non-blocking. e.g. MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) has a callback function(err, db) and is non- blocking.

like image 153
LAX_DEV Avatar answered Nov 30 '25 00:11

LAX_DEV