This package has been deprecated

Author message:

deprecated and archived in favor of the new [mongodb-proper-repository] -- see README.md

mongodb-xcollection

0.2.5 • Public • Published

DEPRECATION NOTICE

This repository has been deprecated and archived in favor of the new mongodb-proper-repository. This means its NPM package will be soon removed.

Read more about here.


mongodb-xcollection

MongoDB extended collection class that frees you from ObjectID and other Extended JSON type conversions.

How to use

Automatic conversion

// considering you already have a `db` variable that is a native driver Db instance

const XCollection = require('mongodb-xcollection');
const Users = new XCollection(db, 'users');

// find
let users1 = await Users.find({ _id: { $oid: '5e332ae5f4744e0b08e510e8' } });

// insertOne
const createdUser1 = await Users.insertOne({ name: 'Gustavo' });

Manual conversion

// find
const findQuery = Users.convertInput({ _id: { $oid: '5e332ae5f4744e0b08e510e8' } });
const users2 = await Users.collection
  .find(findQuery)
  .toArray()
  .then(x => Users.convertOutput(x));

// insertOne
const newUser = Users.convertInput({ name: 'Gustavo' });
const createdUser2 = await Users.collection
  .insertOne(newUser)
  .then(x => Users.convertOutput(x.ops));

Package Sidebar

Install

npm i mongodb-xcollection

Weekly Downloads

0

Version

0.2.5

License

MIT

Unpacked Size

8.06 kB

Total Files

4

Last publish

Collaborators

  • ggondim