Skip to content

NOALVO/mongodb-xcollection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Packages

No packages published