MongoDB Debugging

JS
S
JavaScript

Examples of how to debug queries on MongoDB (official Node.js driver). The pool size determines how many queries may be run using the same connection in parallel Loadtest using a pool size of 3. This means that our database connection will be able to run a maximum of three queries to MongoDB at one time

1// Slow query on purpose
2  db.collection('test').find({'$where': 'sleep(5000) || true'}).toArray(function(err, cursor) {
3    return res.json({"docCount": 'docs'});
4  });
5
6  db.collection('test').countDocuments({}, function(err, count) {
7    return res.json({'documentCount': count});
8  });

Created on 2/5/2021