Complete the code to import the database client module.
const dbClient = require('[1]');
The mongodb module is used to connect to a MongoDB database in Node.js.
Complete the code to connect to the database using the client.
dbClient.connect('[1]', (err) => { if (err) throw err; console.log('Connected!'); });
The connection string for MongoDB starts with mongodb:// followed by the host and port.
Fix the error in the code to properly close the database connection.
dbClient.[1]();The correct method to close a MongoDB client connection is close().
Fill both blanks to create a query that finds all users older than 18.
db.collection('users').find({ age: { [1]: [2] } }).toArray((err, results) => { if (err) throw err; console.log(results); });
The MongoDB query operator $gt means 'greater than'. We want users older than 18.
Fill all three blanks to insert a new user with name and age into the database.
db.collection('[1]').insertOne({ name: '[2]', age: [3] }, (err, res) => { if (err) throw err; console.log('User added'); });
We insert into the 'users' collection a user named 'Alice' who is 30 years old.
