Skip to content
Advertisement

Tag: mongodb

MongoDB find by _id

I’m building a Node.JS app, and i have a function that returns all the records if none of the queries were sent and, if sent, it returns all the records satisfying my query. Here’s my code: Why i got an empty array returned when my param is { _id: ‘5f0218093e6f27870a6d5db2’ }? When I’m querying other properties e.g. { name: ‘1l

TypeError: Order.find is not a function

I am building ecommerce website using MERN stack. And I am getting error while testing using Postman. backend/controllers/user.js backend/models/Order.js backend/models/User.js backend/routes/user.js Error:- TypeError: Order.find is not a function at exports.userPurchaseList (C:UsersRahulMernBootcampprojbackendcontrollersuser.js:47:9) TESTING this route using POSTMAN. Answer You have exported an object so in your backend/controllers/user.js you could import it like so from destructuring from the object then the rest

Mongoose populate subdocument in array

I have a Mongoose offer model explained below: and order schema which has reference to to the first schema offer explained below: the problem that I can not populate sections here {section: { type: Schema.Types.ObjectId, ref: ‘Offer.sections’ }} it gives me MissingSchemaError: Schema hasn’t been registered for model “Offer.sections”. so is there any way to populate sections? Answer Unfortunately, Mongoose

How to get data based on username in cube js

DEFINITION I have connected my cube js backend to mongodb. I am storing documents inside my mongo db database in a following way. THIS IS HOW MY DOCUMENT LOOKS LIKE IN MONGO DB So now let us assume that I have 10 documents in my mongodb collection in which 5 documents belong to user: “abc” and 5 documents belong to

Advertisement