I am trying to save my data to a mongodb server but somehow it force replaces the first variable as id so it is throwing the above mentioned error. in router code I am doing console.log(req.body,cred) and here is the result I get: { emailAddress: ‘test@gmail.com’, password: ‘123456’, id: ‘6070cbd7c603550ac4385485’ } { _id: 6078c61277453c2170d7e177, password: ‘123456’, id: ‘6070cbd7c603550ac4385485’ } Can
Tag: mongoose
join object from another documnt with localfield key
i have a competition doc with field teams array of object with _id of team and a score doc with teamId field competitions.teams = [{_id: 100,..}, {..}] score.teamId = 100 when aggregatig score i want to group it to the competition teams but imm getting all team inside the group innstead of matching id sample document https://mongoplayground.net/p/yJ34IBnnuf5 returns all team
How to test mongoose pre hook ‘save’ and bcryptjs
I trying to create unit tests for mongoose model. I do not think how to test bcryptjs.hash in my schema. This is my User Schema: This is my test: But I have error is: TypeError: Attempted to wrap undefined property hash as function Answer You could mock the bcrypt doing that and your test could use
Terminal hanging while running an asynchronous JS script to populate a Mongoose DB
I’m working on a personal project and am trying to understand the process logic that keeps my Node JS process from terminating after calling populateTransactions(). I think its because I need to close the DB (I’m not entirely clear on why), but when I do, the process terminates but the save() function of the model doesn’t complete and the DB
Conditional joins on collections using mongoose
I’m new to mongoDB, I am trying to achieve the following SQL query on it. but could not find anything useful so far. can anyone tell equivalent mongoose query what I got so far is following UPDATE I have following name and export scheme Answer You can use filter out objects included in resulting array using match but in the
How to make sure that objects do not have the same two element in mongoose schema?
I am making the following mongoose schema and i want to make sure that no object has the same autherFirstName and autherLastName. object may have one in common but not both of them Answer https://mongoosejs.com/docs/2.7.x/docs/indexes.html Create a composite unique index
Not able to get the res.json() value from nodejs server
I am using react.js as frontend and nodejs for the backend. My client-side code is And My server-side code is Front-end output In the server-side code, you can see that I am returning the res.json. but On the client-side, I am not getting the value that I have returned from the server. Please, can anyone help me? Answer You need
mongodb project map fields to return from query with wildcard
I’m working on a system where I use a schema with the type Map much like this: I’m trying to query certain parts of the docs in this collection with a projection: I would like to only get the fields in data starting with xy. Do you have any hint how to do that? Answer Since Mongoose’s map type will
How to exclude an array of objects from mongoose find?
Lets pretend my collection holds following elements: Now I want to execute a find operation but want to exclude following items: How does the query have to look to get the following response? Answer Try $nor operator, performs a logical NOR operation on an array of one or more query expression and selects the documents that fail all the query
How do I query the database using Mongodb after I set up a Mongoose schema for authentication?
I successfully set up authentication for my app, which is a node.js (Express) app. I used Passport-local and I also used a Mongoose schema. The folder structure is like this: Inside the “models” folder is the User.js file, and it contains this schema: And the app.js (the main file) includes the following code. I am not showing everything by the