Skip to content
Advertisement

Tag: mongoose

MongoDB Problems while inserting nested data

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 Atlas I have 2 collections

“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.stack.imgur.com/xss8j.png Answer So… idk why this works but I forgot to make the profile picture

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 html sanitizer like

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 database and it crashes the server giving the

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 push the objects back into the items

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() and the second one without using save(), and they all did the same

Advertisement