Database
You can interact with your database with normal MongoDB commands. Make sure you select the Database checkbox which will import the db at the top of your file:
import { db } from("swizzle-js");The db variable is a pre-connected instance of your mongo database. You can make any MongoDB query on it, for example:
Find - Retrieves all documents from the
studentscollection where thegradeis "senior".const seniorStudents = await db.collection('students').find({ grade: "senior" }).toArray();Update - Updates the first document in the
studentscollection with thename"Alice" to set herageto 26.const updateResult = await db.collection('students').updateOne({ name: "Alice" }, { $set: { age: 26 } });Insert - Inserts a new user document into the
studentscollection.const newStudent = { name: "Bob", age: 18, email: "[email protected]" }; const insertResult = await db.collection('students').insertOne(newStudent);Count - Counts the number of documents in the
studentscollection where theageis greater than 18.const count = await db.collection('students').countDocuments({ age: { $gt: 20 } });
Last updated