Created
May 14, 2020 08:49
-
-
Save urcoilbisurco/17088200a181612b803a976aec201ecb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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