5.4.1 • Published 6 years ago

modern-mongo v5.4.1

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

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

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.0

6 years ago

5.0.0

6 years ago

4.4.3

7 years ago

4.4.1

7 years ago

4.4.0

7 years ago

4.3.2

7 years ago

4.3.1

7 years ago

4.2.0

7 years ago

4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.2.0

8 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.6.1

9 years ago

2.5.0

9 years ago

2.4.0

10 years ago

2.3.1

10 years ago

2.3.0

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago