Logical Query Operator using Mongoose
this imformation copyright by mongoDB.com official website.
| $and | Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. |
| $not | Inverts the effect of a query expreassion and returns documents that do not match the query expression. |
| $nor | Joins query clauses with a logical NOR retures all documents that fail to match both clauses |
| $or | Joins Query clauses with a logical OR returns all documents that match the conditions of either clause. |
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 creation// in model("collection name", define schema)const PlayList = new mongoose.model("PlayList",playlistSchema)// get all data inside Databaseconst getDocument = async()=>{try {const result = await PlayList.find({$or : [{roll : 483}, {roll : 583}]});// .select({name:1})console.log(result);}catch(err){console.log(err);}}getDocument();
connction successful...
[
{
_id: new ObjectId("61cc0946c62a51adf6bc23d9"),
name: 'Shreyash',
sirname: 'KOlhe',
email: 'shreyashkolhe2001@gmail.com',
role: 'front-end',
active: true,
date: 2021-12-29T07:07:50.874Z,
__v: 0,
roll: 483
},
{
_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
}
]
Post a Comment