Mongoose
yarn add mongooseSetup
const mongoose = require('mongoose');
const mongoDB = 'mongodb://127.0.0.1/my_database';
mongoose.connect(mongoDB);
//usually mongoose uses pseudo promises, this tells it to use real ones
mongoose.Promise = global.Promise;
//Get the default connection
const db = mongoose.connection;
//Bind connection to error event (to get notification of connection errors)
db.on('error', console.error.bind(console, 'MongoDB connection error:'));Defining Models
Schema Types
Using Models
Creating
Querying
Count
Advanced
Model Instance Methods
Upsert
References
Callback Style
Last updated