Created
June 6, 2023 08:50
-
-
Save sezanzeb/1cdad9484eb5ecd4736c76ddbac6b410 to your computer and use it in GitHub Desktop.
MongoDB Quickstart / hello-world
This file contains 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
// 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