Skip to content

Instantly share code, notes, and snippets.

@sezanzeb
Created June 6, 2023 08:50
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 sezanzeb/1cdad9484eb5ecd4736c76ddbac6b410 to your computer and use it in GitHub Desktop.
Save sezanzeb/1cdad9484eb5ecd4736c76ddbac6b410 to your computer and use it in GitHub Desktop.
MongoDB Quickstart / hello-world
// docker run --name mongodb -d -p 27017:27017 mongodb/mongodb-community-server:latest
const { MongoClient } = require('mongodb')
async function main() {
const mongoClient = await MongoClient.connect('mongodb://localhost:27017/')
const db = mongoClient.db('test')
const collection = db.collection('test')
await collection.insertOne({
'hello world': 'foo'
})
const documents = await collection.find({}).toArray()
console.log(documents)
mongoClient.close()
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment