From 6a5fefd4c3724054fe8831dfdb9544c31608fb05 Mon Sep 17 00:00:00 2001 From: Enok <416828041@qq.com> Date: Wed, 4 Mar 2020 15:50:38 +0800 Subject: [PATCH] add example doc --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a038bc3b..b2be2d34 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,26 @@ ## Examples ```ts -// TODO +import { init, MongoClient } from "https://deno.land/x/mongo/mod.ts"; + +// Initialize the plugin and specify the binary release version (because the binary currently has no idea how to associate the version in ts and the binary) +await init("0.1.0"); + +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" +}); + +// findOne +const user1 = await users.findOne({ _id: insertId }); + +// deleteOne +const deleteCount = await users.deleteOne({ _id: insertId }); ```