I try to build a database for a giveaway bot using MongoDB. Once a new giveaway is created the bot runs the following code to write the new giveaway into the databank: Giveaways should be a nested document in the document with the server’s information. My schemas for this looks like this: In my Mongo At…
Tag: mongoose
“TypeError: Cannot read properties of undefined (reading ‘hasOwnProperty’)” error
EDIT: PROBLEM SOLVED. I’m trying to make an update profile page for an Express app with Mongoose, and I got the error “TypeError: Cannot read properties of undefined (reading ‘hasOwnProperty’)”. I am confused how to fix it. Here is my code, thanks (error shown) [1]: https://i.sta…
Mongoose how to count unique days in a month?
i am working on a problem where in my database there supposed to be multiple entries from day to day. each entry includes a timestamp. the problem is im supposed to find how many days in each month a data has been entered. ex: if a user sends a message every 2 days in may. my answer would be: “the
how to only update specific fields and leave others with the previous values in findandupdate with Mongoose
I’ve created an update function using Mongoose. However whenever I update the data using findOneAndUpdate. It updates only the fields entered and making it so that the others are now null or empty. I would like it so that when the user is updating and they dont update a filed it should remain as what it…
How do I export mongodb html code to html file?
How do I display an html data piece from mongo db correctly? Data: The html was encoded What it shows: Not showing correctly Code: Answer Not really sure why you put that html on a textarea element. But if the content is comming from a database that is contain use generated content, then you probele need an h…
Mongodb Compare two fields with ratio
Rows whose field is twice that of the other field explain with example : I want row that spend is equal or bigger twice price (spent >= 2*price) result : {id : 1 , price : 40 , spent : 90} ==> (spent >= 2price) [90>80]* {id : 1 , price : 80 , spent : 200} ==> (spent >=
Uploading an image to an API with multer
I’m trying to make an application that requires image uploading and storing, I’m using Express, Mongoose and Multer and trying to upload to MongoDB. Currently when I try to upload an image, Multer does create a folder and store the image in that folder, but it doesn’t save the item to the da…
How to return sorted array from object from MongoDB document?
I want to return an array, which is a property inside my mongo model/document, and I want that array to be sorted. My MongoDB document looks like: And I’m trying to return: I have tried aggregation: Answer Mongo Playground reference Since $unwind returns the arrays as objects, we are using the $group to…
How do I get the same parent result regardless of the order of children being queried? (One to Many)
I’m building a chat with private rooms. What I’m trying to do is find a room that two users belong too. If there isn’t one create one. Chat Schema Query Controller The problem I’m having The order of the auth and receiver changes depending who is logged in and produces a different quer…
What’s the point of using save() in Mongoose?
I’m learning MongoDB and Mongoose, and I’ve watched instructors advise to use the save() function to save the changes made to the database. But I’m still making changes successfully without using save(). I’ve made two functions to add a document to the database, one with using save() a…