I was working on a project with MongoDB and passport, when i ran into this error, event though p1 isn’t used, it still reruns an object im guessing, because it just says that the field p1 is taken, when it isn’t. The same is happening with p2. Does anyone know why ? Answer Calling User.find returns a Promise which you
Tag: mongodb
Mongoose – get documents with best score but only one of each user
So this is how my mongoose schema looks like: This is a quiz application so there are multiple documents with same userId. I am trying to make a query to build leaderboard and I came up with this. Now because I want to show only top 10 users, I have added .limit(10). Now in these 10 documents, there is chance
mongoose aggregate model based on filter
I have a model of Review which has the field product and rating I would like to find the sum of all ratings of a specified product and find the average by dividing by 5. how would I aggregate through all ratings and filter by product to find the sum? Answer I’m assuming your using nodejs , here is how
User ID won’t save into session after a log in
I’m new to coding and I’m trying to write one of my first apps. I encountered a problem with my log in function. The user id saves into my session object after user registration but it won’t save into it after a log in. I’m using MongoDB. Here is the code: Controller Model Screenshot of the console – registration Screenshot
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
Type Error : Cannot read property ‘name’ of null [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 2 years ago. Improve this question
MongoDB: How to append to a string in a deep nested array
I’m a hobbyist web programmer who just started learning MongoDB/Mongoose and I can’t seem to figure out how to append to a string located in a deep nested array. I am trying to append a string to the end of hours: String. Below is the Schema I’m working with: Here is what I have so far. I tried to extend