npm.io
3.6.0 • Published 1 year ago

@parameter1/mongodb-core

Licence
MIT
Version
3.6.0
Deps
1
Size
4 kB
Vulns
0
Weekly
0

MongoDB Core

A MongoDB wrapper containing core utilities.

Installation

yarn add @parameter1/mongodb-core

Usage

Core

import { MongoClient } from '@parameter1/mongodb-core';

const client = new MongoClient('mongodb://some-server:27071');

client.connect().then(() => console.log('connected'));

Utilities

import { filterMongoURL, iterateMongoCursor, MongoClient } from '@parameter1/mongodb-core';

// strips user names and passwords from mongo URLs
const client = new MongoClient('mongodb://user:password@some-server:27071');
// logs `mongodb://*****:*****@some-server:27071`
console.log(filterMongoURL(client));


// iterates over a mongo cursor
const cursor = await client.db('test').collection('foo').findMany({});

await iterateMongoCursor(cursor, async (doc) => {
  // do things here... can await
  await someThing(doc);
});