Answers for "mongoose get all documents in collection"

3

get all data in collection mongodb

db.collection_name.find().pretty()
Posted by: Guest on November-04-2020
1

find all mongoose

//create model students

const mongoose = require("mongoose");

const Schema = mongoose.Schema;

const StudentSchema = new Schema({
  name: String,
  dob: Date,
  mobile: String,
  address: String,
});

module.exports = mongoose.model("students", StudentSchema);


const STUDENT = require("../models/Student");


exports.getProducts = (req, res, next) => {
	//fetch all student data
  STUDENT.find().then((p) => {
    res.send(p);
  });
};

exports.getProducts = (req, res, next) => {
	//fetch all student data 
  STUDENT.find({},(err,p)=>{
  	 res.send(p);
  });
};
Posted by: Guest on April-28-2021
0

mongoose get all documents big

var query = templateData.find({}).stream();
query.on('data', function (doc) {
    // do something with the mongoose document
}).on('error', function (err) {
    // handle the error
}).on('close', function () {
    // the stream is closed
});
Posted by: Guest on May-11-2020

Code answers related to "mongoose get all documents in collection"

Browse Popular Code Answers by Language