how to fetch data from mongodb in node js using mongoose code example

Example 1: not fetch data from mongoose

//All objects add 's' behind => 'student' to 'students' 

const mongoose = require("mongoose");

const Schema = mongoose.Schema;

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

// tat ca phai them chu s dang sau
module.exports = mongoose.model("students", StudentSchema);

Example 2: get data from mongodb node js using mongoose

//Require Mongoose
var mongoose = require('mongoose');

//Define a schema
var Schema = mongoose.Schema;

var SomeModelSchema = new Schema({
  a_string: String,
  a_date: Date
});

Example 3: get data from mongodb node js using mongoose

Athlete.
  find().
  where('sport').equals('Tennis').
  where('age').gt(17).lt(50).  //Additional where query
  limit(5).
  sort({ age: -1 }).
  select('name age').
  exec(callback); // where callback is the name of our callback function.