Why $or is not working properly in mongoose with regular expression

I’m trying to fetch documents which contain whatever I pass in url for filter which must present in title field or in tasks array of those documents: example: localhost:4000/search?filter=Morning. here I’m looking for documents which contain Morning in their title or in their tasks. But when I’m hitting the Api it is returning me all… Read More Why $or is not working properly in mongoose with regular expression

.save is not a function in Mongoose

What is wrong with the way I am using Mongo? I am simply trying to update a record. Here is my code: async function updateReview (req, res) { const review = { …req.body } const existingReview = await Review.findOne({ userId: review.userId, launchId: review.launchId }).lean() if (!existingReview) { return res.status(404).send() } existingReview.content = review.content existingReview.displayName =… Read More .save is not a function in Mongoose

How to load referenced document in Mongoose?

I have a MongoDB collection called categories which has a self-reference(parent) like follows. const schema = mongoose.Schema({ name: String, parent: { type: mongoose.Schema.Types.ObjectId, ref: ‘Category’, } }); export default mongoose.model(‘Category’, schema); When i query it just returns the object id of the referenced document. { "_id": "63731fe1ce1bf2f534f9307e", "name": "Glass cleaners", "parent": "63731fbbce1bf2f534f9307d", } I want… Read More How to load referenced document in Mongoose?

how to count two same property with different values in mongoose?

first, i should say that im new to mongoDB and mongoose ODM. my question: each document of my documents is something like this: { "_id": { "$oid": "6353f73c97588e3864eaa635" }, "text": "test!", "date": "10/22/2022, 2:52:52 PM", "isCompleted": false } they have isComplete property that can be true or false. now i want to count documents with… Read More how to count two same property with different values in mongoose?

Update value inside array of object in mongoose

I have a notification schema in mongoose: var mongoose = require(‘mongoose’); var schema = mongoose.Schema; var notificationSchema = new schema({ createdOn:{type: Date, default: Date.now}, createdBy:{type: String, required:true}, sentTo:{type: Array, required:true}, content:{type:Object} }); module.exports = mongoose.model(‘notification’,notificationSchema); data would be like this : { "_id" : ObjectId("6350dee274edf5586dc86099"), "sentTo" : [ { "username" : "user1", "status" : 0… Read More Update value inside array of object in mongoose

Mongoose Find() – Return all docs if query is undefined

I have mongoose Find code function , the query is recieved from params (Here currently hardcoded) Suppose this as the query var arrayOfCategories = [ ‘63073212ed3e0f85ccffc8cf’ , ‘63073324ed3e0f85ccffc8ff’] var arrayOfSkill = [] This is my find code const astro =await Astrologer.find({ ‘category.astolCat_id’ : {$in: arrayOfCategories}, ‘skills.astolSkill_id’: { $in: arrayOfSkill}}) It works fine if I have… Read More Mongoose Find() – Return all docs if query is undefined

Mongoose return all documents that contain a value wherever inside a property

Lets say my documents look like this : _id: "6285e9a7aff93ead37ec50ad", date: "2022-04-28T10:51:37.923Z", devices: { tablets: [ { brand: "samsung", model: "s20" }, { brand: "samsung", model: "s21" }, { brand: "apple", model: "ipad_mini" }, ], phones: [ { brand: "samsung", model: "galaxy_s20" }, { brand: "samsung", model: "galaxy_s20_lite" } ], laptops: [] } } how… Read More Mongoose return all documents that contain a value wherever inside a property

In mongodb. I have One object inside ids of user array , Now I want to lookup for that ids in related users details, with aggregation

{ "_id": "61efc2c437c455b7216629ff", "event_images": [ "1643102858880rn_image_picker_lib_temp_38cdc02f-4207-446a-9263-1e6914954095.jpg" ], "distance": 80, "ratio_men": 50, "ratio_women": 60, "ratio_others": 30, "invite_users": [ "61e6830ae88d1929e3d239f9", "61e6830ae88d1929e3d239f9", "615ae0e5da07c2f5d777248b", "615ae0e5da07c2f5d777248b", "61e7beaae88d1929e3627c69", "61e7beaae88d1929e3627c69" ], "notinvited_users": [], I have Invited user array inside the array i have ids, I want to lookup the user detail with these ids >Solution : do it yourself you can do… Read More In mongodb. I have One object inside ids of user array , Now I want to lookup for that ids in related users details, with aggregation