Comparison Query operator using Mongoose
For Comparison of different BSON type values, see
| Name | Description | 
| $eq | equeal to a specified value | 
| $gt | greater than a specified value | 
| $gte | greater than equal to a specified value | 
| $in | Matches any of the values specified in an array | 
| $lt | less than a specified value | 
| $lte | less than or equal to a specified value | 
| $ne | Matches all values that are not equal to specified value | 
| $nin | Matches none of the values specified in an array | 
$gt
const mongoose = require('mongoose');mongoose.connect("mongodb://localhost:27017/newDB",{useNewUrlParser: true}).then(()=>{console.log("connction successful...")}).catch((err)=>console.log(err));const playlistSchema = new mongoose.Schema ({// define schemaname:{type : String,required : true},sirname : String,email : String,role : String,active : Boolean,date : {type: Date,default : Date.now},roll : Number,})// collection creationconst PlayList = new mongoose.model("PlayList",playlistSchema)// get all data inside Databaseconst getDocument = async()=>{try {const result = await PlayList.find({roll: {$gt : 500}})// .select({name:1})console.log(result);}catch(err){console.log(err);}}getDocument();
connction successful...
[
  {
    _id: new ObjectId("61cc0946c62a51adf6bc23da"),
    name: 'Vaibhav',
    sirname: 'Bandal',
    email: 'vaibhav@gmail.com',
    role: 'front-end',
    active: true,
    date: 2021-12-29T07:07:50.876Z,
    __v: 0,
    roll: 583
  },
  {
    _id: new ObjectId("61cc0946c62a51adf6bc23dc"),
    name: 'amit',
    sirname: 'badhe',
    email: 'amit@gmail.com',
    role: 'front-end',
    active: true,
    date: 2021-12-29T07:07:50.878Z,
    __v: 0,
    roll: 683
  }
]
Post a Comment