how to fetch data from mongodb in node js using mongoose code example
Example 1: not fetch data from mongoose
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);
Example 2: get data from mongodb node js using mongoose
var mongoose = require('mongoose');
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).
limit(5).
sort({ age: -1 }).
select('name age').
exec(callback);