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
Tag: mongodb
Is new keyword is necessary with ObjectID in MongoDB Query
I was working on a Typescript web project that used MongoDB and ExpressJS. I used a MongoDB query to find and delete a document from MongoDB using the HTTP DELETE method. During the MongoDB query, I got mixed up with a term named new and ObjectID. Here are the code snippets: Both are working fine as I expected. But I
Mongodb: How to group the result of a $lookup and map them to a list objects that contain a matching key?
I have classroom document which contain ‘modules’, the whole document looks like this: I also have assignment documents as such: My question is how could do aggregation such that if I want to do a lookup on the assignments for the classroom, I am able to group the assignment documents by moduleId and then add them as a field to
MissingSchemaError: Schema hasn’t been registered for model “User, userSchema”. Use mongoose.model(name, schema)
hope you’re doing well. i’m following a tutorial ( from 2019 ), and i’m facing this error at the moment. here’s the code. ( let me know if you need anything else ) // index.js // // User.js // // auth.js // Thank you in advance. The Lord be with you and save you all, your families and friends 🙂
JSON empty when is called from another file
I’m learning NodeJS and MongoDB. I dont know what is happening with this function. If I make a console.log before return user, it works fine (just print an JSON array with all info of the collection) The problem is when I call it from another file (in my case, the router). If I do this, I receive an empty json.
Axios request works only on second request
I am building a user login system and currently the way I have it set up, the user types in their email and password and then that information is sent to my server to be checked if accurate. If it is, I create a JWT token and send it back along with the mongodb _id of the user, I then
MongoDb query return empty object
I’m trying to perform a simple .find() query on my mongodbAtlas, but the result of this query is an empty object. this is my server file: this is my routes file: this is how my document is populated: Answer I think you are missing the “await” keyword after const data….. as API data fetching calls are asynchronous and required promise/
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
Storing API Keys in react-native app with expo library
I have a question, please, if possible explain in simple terms. Im new to react native, what’s the best way to store API keys in a secure way where they can’t reverse engineer it and get the keys right away. Can I just retrieve it from the server side using a restapi to get the apikey only if user is
How to Wait Until a MongoDB Connection is Made before Using the Database
I have the following code to create a connection to my MongoDB database, and to store it for future use. My problem is that _database is undefined until the connection is made. If my website tries to use the database before _database is defined it will throw an error and crash. I want to make it so instead of crashing,