Skip to content

Instantly share code, notes, and snippets.

@urcoilbisurco
Created May 14, 2020 08:49
Show Gist options
  • Save urcoilbisurco/17088200a181612b803a976aec201ecb to your computer and use it in GitHub Desktop.
Save urcoilbisurco/17088200a181612b803a976aec201ecb to your computer and use it in GitHub Desktop.
import { init, MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
// Initialize the plugin
await init();
const client = new MongoClient();
client.connectWithUri("mongodb://localhost:27017");
const db = getClient().database("test");
const users = db.collection("users");
// insert
const insertId = await users.insertOne({
username: "user1",
password: "pass1"
});
// insertMany
const insertIds = await users.insertMany([
{
username: "user1",
password: "pass1"
},
{
username: "user2",
password: "pass2"
}
]);
// findOne
const user1 = await users.findOne({ _id: insertId });
// find
const users = await users.find({ username: { $ne: null } });
// count
const count = await users.count({ username: { $ne: null } });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment