Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

alibaba-archive/mongodb-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongodb-client

NPM version build status Test coverage David deps npm download

A nice API client for MongoDB.

Features

  • Make API as same as MongoDB CRUD Reference
  • Reading the source codes just like reading the document of MongoDB client.
  • Fix native mongodb insertedIds data format error on options.ordered = false.
  • Remove insert() method, please use the more clear insertMany() and insertOne() instead.
  • Disable options.forceServerObjectId on write methods.
  • ...

Installation

$ npm install mongodb-client

Quick start

const co = require('co');
const MongoDB = require('mongodb-client');

const db = new MongoDB('mongodb://localhost:27017/myproject');
// listen db connect error event
db.on('error', err => {
  console.error(err);
});
// wait for db connected
db.ready(() => {
  // let's read and write
  co(function*() {
    const result = yield db.collection('user').insertMany([
      { name: 'fengmk2', type: 'JavaScript' },
      { name: 'dead-horse', type: 'JavaScript' },
      { name: 'tj', type: 'go' },
    ]);
    console.log(result);

    const docs = yield db.collection('user').find({ type: 'JavaScript' }).skip(10).toArray();
    console.log(docs);
  }).catch(err => {
    console.error(err);
    console.error(err.stack);
  });
});

License

MIT


APIs

CURD

Insert Documents

TBD

Modify Documents

TBD

Query Documents

TBD

Remove Documents

Indexes

TBD

Aggregation

TBD

Administration

TBD