1//create model students
2
3const mongoose = require("mongoose");
4
5const Schema = mongoose.Schema;
6
7const StudentSchema = new Schema({
8 name: String,
9 dob: Date,
10 mobile: String,
11 address: String,
12});
13
14module.exports = mongoose.model("students", StudentSchema);
15
16
17const STUDENT = require("../models/Student");
18
19
20exports.getProducts = (req, res, next) => {
21 //fetch all student data
22 STUDENT.find().then((p) => {
23 res.send(p);
24 });
25};
26
27exports.getProducts = (req, res, next) => {
28 //fetch all student data
29 STUDENT.find({},(err,p)=>{
30 res.send(p);
31 });
32};
33
34
1// Find the adventure with the given `id`, or `null` if not found
2await Adventure.findById(id).exec();
3
4// using callback
5Adventure.findById(id, function (err, adventure) {});
6
7// select only the adventures name and length
8await Adventure.findById(id, 'name length').exec();
1// include a and b, exclude other fields
2query.select('a b');
3// Equivalent syntaxes:
4query.select(['a', 'b']);
5query.select({ a: 1, b: 1 });
6
7// exclude c and d, include other fields
8query.select('-c -d');
9
10// Use `+` to override schema-level `select: false` without making the
11// projection inclusive.
12const schema = new Schema({
13 foo: { type: String, select: false },
14 bar: String
15});
16// ...
17query.select('+foo'); // Override foo's `select: false` without excluding `bar`
18
19// or you may use object notation, useful when
20// you have keys already prefixed with a "-"
21query.select({ a: 1, b: 1 });
22query.select({ c: 0, d: 0 });
1exports.generateList = function (req, res) {
2 subcategories
3 .find({})//grabs all subcategoris
4 .where('categoryId').ne([])//filter out the ones that don't have a category
5 .populate('categoryId')
6 .where('active').equals(true)
7 .where('display').equals(true)
8 .where('categoryId.active').equals(true)
9 .where('display').in('categoryId').equals(true)
10 .exec(function (err, data) {
11 if (err) {
12 console.log(err);
13 console.log('error returned');
14 res.send(500, { error: 'Failed insert' });
15 }
16
17 if (!data) {
18 res.send(403, { error: 'Authentication Failed' });
19 }
20
21 res.send(200, data);
22 console.log('success generate List');
23 });
24 };