Category : mongoose

i have added code to add client to mongodb collection however http://localhost:9001/saveClients returning the bad request error 400, any idea what could possibly implemented wrong here ? console.log("CLIENTS POST >>>>>", req.body); printing empty object controller.ts public static async save (req: Request, res: Response): Promise<any> { try { console.log("CLIENTS POST >>>>>", req.body); const clientData = req.body; ..

Read more

I want to update data in MongoDb. If I console.log the data that I want to update in it appears, but it won’t update. Also in Insomnia I’m getting "No body returned for response". Here is my update code : const Organizer = require("../models/OrganizerModal"); router.put("/update/:id", auth, async (req, res) => { console.log(req.body); const userId = ..

Read more

Good afternoon, I am trying to change the remainder of the product in mongoose in a loop. But persistence doesn’t work. I would be grateful for your help! const statusOutOfStock = await ProductStockStatus.findOne({ color: ‘danger’, }) for await (const product of Product.find()) { const orderItems = order.orderItems.filter( item => String(item.product) === String(product._id) ) if (orderItems?.length ..

Read more

const dbConfig = require("../config/config.js"); const mongoose = require("mongoose"); mongoose.Promise = global.Promise; const db = {}; db.mongoose = mongoose; db.url = dbConfig.url; db.Users = require("./users.model.js")(mongoose); db.Listservices = require("./listservices.model.js")(mongoose); db.Services = require("./services.model.js")(mongoose); db.Reviewservices = require("./reviewservices.model.js")(mongoose); module.exports = db; listservices.model.js module.exports = mongoose => { const Listservices = mongoose.model( "listservices", mongoose.Schema( { type: String, services_name: String, image: String, ..

Read more

Can anyone suggest me how to get unique value from object so far I`m able to get it by doing these const address = await Property.find({address:{$regex: req.body.tag, $options: ‘i’}}).where(‘offerType’).equals(req.params.type).select(‘city address offerType district property_id’).lean(); const district = await Property.find({district:{$regex:req.body.tag,$options: ‘i’}}).where(‘offerType’).equals(req.params.type).select(‘city district ‘).lean(); let data =[] district.forEach(element => { var i = data.findIndex(x => (x.district == element.district ..

Read more