concept

Mongoose is an open source packaged data modeling library for data communication between Node and MongoDB.

The installation

npm install mongoose –save

Connecting to a Database

Build a link database

Schema Model Document

Schema

Mongoose Schema defines the collection fields and types of Mongodb collection. All contents in Mongoose start with Schema, and each Schema is mapped to the Mongdb collection, and the structure of documents in the collection is defined.

Model

Examples of models generated by Schema are called documents. Generally used to query documents from Mongodb, modify documents, delete documents.

Document

One-to-one mapping with documents in Mongodb, where each document is an instance of its model, is generally used to take care of storing documents in Mongodb.

Schema types

String,Number,Date,Boolean,Array,ObjectId,Buffer,Mixed,Decimal128,Map

Save the document

Modify the document

  • Modify by ID
  • Modify according to conditions

Delete the document

Delete by ID

Delete by condition

Query the document

Query by ID

Query by condition

  • Query all
  • Range queries
  • Blur or query
  • And the query
  • Paging query