Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Created March 9, 2022 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevincennis/42563f84a1918f1026f3df8110149ac0 to your computer and use it in GitHub Desktop.
Save kevincennis/42563f84a1918f1026f3df8110149ac0 to your computer and use it in GitHub Desktop.
deno node compat mongo demo
npm i
deno run --unstable --compat --allow-all index.j
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/denotest';
const opts = { useNewUrlParser: true, useUnifiedTopology: true };
async function main() {
const client = await MongoClient.connect( url, opts );
const db = await client.db();
const coll = await db.collection('testypoo');
const res = await coll.insertOne({ foo: 'bar' });
const doc = await coll.findOne({ _id: res.insertedId });
console.log( doc );
await client.close();
}
main().then( console.log, console.error );
{
"name": "denomongo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mongodb": "^4.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment