Complete the code to connect to MongoDB using Deno.
import { MongoClient } from "https://deno.land/x/mongo@v0.31.1/mod.ts"; const client = new MongoClient(); await client.[1]("mongodb://localhost:27017");
The connect method is used to establish a connection to the MongoDB server.
Complete the code to select the database named 'testdb'.
const db = client.[1]("testdb");
The database method is used to select a database by name in Deno MongoDB client.
Fix the error in the code to get a collection named 'users'.
const users = db.[1]("users");
The correct method to get a collection is collection. Other options are incorrect or do not exist.
Fill both blanks to insert a document with name 'Alice' and age 30 into the 'users' collection.
await users.[1]({ name: "Alice", age: [2] });
Use insertOne to insert a single document. The age value should be 30 as given.
Fill all three blanks to find all users older than 25 and print their names.
const cursor = users.[1]({ age: { [2]: [3] } }); for await (const user of cursor) { console.log(user.name); }
The find method queries documents. The operator $gt means 'greater than'. We want age greater than 25.
