
My collection of JS/TS snippets
← Back to list
Posted on 10.06.2020
Last updated on 03.02.2025
Image by Marcin Wichary on Flickr
Refill!
Here I have a collection of useful JS/TS snippets used in profession day to day work routine.
While crawling the official docs, could not find a working example of how to extract data from a database. The snippet below is basically a compilation of some posts from Stackoverflow:
#!/usr/bin/env nodeconst MongoClient = require('mongodb').MongoClient;const MONGO_URI = 'mongodb://localhost:27017/?maxPoolSize=20&w=majority';const client = new MongoClient(MONGO_URI);async function run() {try {const connection = await client.connect();const database = connection.db('db_name');const registry = database.collection('collection_name');const result = await registry.find({}).toArray();console.log(result);} finally {await client.close();}}run().catch(console.dir);
The code is licensed under the MIT license

Sergei Gannochenko
Business-focused product engineer, in ❤️ with amazing products.
Golang/Node, React, TypeScript, Docker/K8s, AWS/GCP, NextJS.
20+ years in dev.
Golang/Node, React, TypeScript, Docker/K8s, AWS/GCP, NextJS.
20+ years in dev.