Complete the code to insert a document with a string field in MongoDB.
db.collection.insertOne({ name: [1] })The name field expects a string value, so we use quotes around the text.
Complete the code to insert a document with a boolean field in MongoDB.
db.collection.insertOne({ active: [1] })The active field is a boolean, so we use the boolean value true without quotes.
Fix the error in the code to insert a document with a date field in MongoDB.
db.collection.insertOne({ createdAt: [1] })new Date() inside quotes, making it a string.Date() without new, which returns a string.To store a date in BSON, use new Date() which creates a Date object. Quoting it makes it a string, which is incorrect.
Fill both blanks to create a document with an ObjectId and a null field.
db.collection.insertOne({ _id: [1], deletedAt: [2] })undefined instead of null.new ObjectId() which is valid but not the preferred shorthand here.The _id field uses ObjectId() to create a unique ID. The deletedAt field is set to null to show no deletion date.
Fill all three blanks to create a document with a binary data field, a decimal number, and an array.
db.collection.insertOne({ data: [1], price: [2], tags: [3] })Buffer.from which is Node.js specific, not BSON.BinData stores binary data in BSON. Decimal128 stores precise decimal numbers. Arrays are represented with square brackets.