Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

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));

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages