Get all items in collection Get all items in collection mongoose mongoose

Get all items in collection


In order for Mongoose to return a Promise you need to set this accordingly in your Mongoose instance:

const mongoose = require('mongoose');mongoose.Promise = global.Promise;

Furthermore, if you want to create multiple documents at once, you should pass an array to the .create method:

let things = [  {    "name": "Thing 1"  },  {    "name": "Thing 2"  },  {    "name": "Thing 3"  }];Thing.create(things).then(newThings => {  console.log(newThings);});// Outputs[ { name: 'Thing 1', _id: 57fd82973b4a85be9da73b25 },  { name: 'Thing 2', _id: 57fd82973b4a85be9da73b26 },  { name: 'Thing 3', _id: 57fd82973b4a85be9da73b27 } ]