modern-mongo
Modern interface for MongoDB. Written in ES8.
Last updated 10 months ago by schornio .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install modern-mongo 
SYNC missed versions from official npm registry.

Modern Mongo

Build Status

Class interface for MongoDB.

Installation

npm install modern-mongo

Environment

  • MONGODB_CONNECTION: mongodb connection string, must be provided

Example

1. Create Document subclass

class Person extends Document {

  constructor() {
    super(customJsonSchema);
  }

  // Create custom methods

}

2. Create Collection subclass


class PersonCollection extends Collection {

  constructor() {
    super(Person);
  }

  // Create custom methods

}

Note: mongodb collection name is the provided document name to lower case. (In this example 'person')

3. Use your subclasses

let persons = new PersonCollection();
let person = new Person();

person.name = 'Thomas';
person.hobbies = [ 'programming', 'running', 'gaming' ];

await persons.insertOneSafe(person);

Test

Environment

  • MONGODB_CONNECTION: string, MongoDB-Connection-String

Command

npm test

API

class Document

  • getCollection ()
  • setCollection (collection)
  • getSchema ()
  • setSchema (schema)
  • getValidator ()
  • validate ()
  • applyBareObject (bareObject)
  • async setFields (fields, safe)
  • async setFieldsSafe (fields)
  • async incrementFields (fields)
  • async incrementFieldsSafe (fields)
  • async deleteDocument ()

class Collection

  • newDocument ()
  • async findOne (...args)
  • async findOneById (_id)
  • async findMany (...args)
  • async findManyByIds (_ids)
  • async findOneAndUpdateUnsafe (...args)
  • async insertOne (doc, options, safe)
  • async insertOneSafe (doc, options)
  • async insertMany (docs, options, safe)
  • async insertManySafe (docs, options)
  • async updateOneUnsafe (...args)
  • async updateManyUnsafe (...args)
  • async deleteOne (...args)
  • async deleteMany (...args)
  • async count (...args)
  • async exists ()
  • async createIndex (...args)
  • async indexExists (...args)
  • async drop (...args)
  • async dropIfExists (...args)

Current Tags

  • 5.4.1                                ...           latest (10 months ago)

28 Versions

  • 5.4.1                                ...           10 months ago
  • 5.3.0                                ...           10 months ago
  • 5.2.0                                ...           a year ago
  • 5.1.0                                ...           a year ago
  • 5.0.0                                ...           a year ago
  • 4.4.3                                ...           2 years ago
  • 4.4.1                                ...           2 years ago
  • 4.4.0                                ...           2 years ago
  • 4.3.2                                ...           2 years ago
  • 4.3.1                                ...           2 years ago
  • 4.2.0                                ...           2 years ago
  • 4.1.2                                ...           2 years ago
  • 4.1.1                                ...           2 years ago
  • 4.1.0                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.2.0                                ...           3 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.6.1                                ...           4 years ago
  • 2.5.0                                ...           4 years ago
  • 2.4.0                                ...           4 years ago
  • 2.3.1                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 29
Dependencies (4)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |