I’m trying to singin with existing user but it shows Cannot POST /api/signin. The same works with signup process and I did cross check the signin route but couldn’t find where exactly the issue occurs. signin code: router : router.get(‘/signin’,signin) app: app.use(‘/api’,authRoutes); Tried calling postman with : localhost:2000/api/signin but dint work. The same route pattern for signup worked localhost:2000/api/signup Answer
Tag: mongoose
ValidationPipe doesn’t strip given object in Nestjs
I’m using Nestjs and Mongoose orm the problem is ValidationPipe doesn’t delete invalid props from request and send given(raw) request to my service. This is main.ts and this is update-category.dto And finally this is category.service Here is my simple controller when “given categories” logs items, they have _id which frontend sent to api while I didn’t whitelisted that props in
Using new collections for each user
I am building an Expense Tracking app using Node.js where all the Income and Costs should get saved in a database. My idea is to create a new collection for each registered user and save all their income/cost actions in that collection. The things i would like to consider before writing it are: how do i name the collections Efficiency
Get access to the “current element” when traversing a mongoDB (mongoose) array
I have a mongoose model for a “social media like post” (called PostModel) that has this schema: I simply want to know the number of likes each comment got when querying for a post. This should not be as annoying and difficult as it is. I have spent more than 4 hours on this. What I have tried so far:
Server data coming through as [Object object] on client
I’m trying to display my data being sent from the server but it’s not coming through properly (see [Object object] in the bottom left of the image above). Here’s the client side code: The server is sending the data in an array in below format: I want the values from totalGuests and attendedGuests to display on the client. Here’s my
Not able to connect MongoDB Atlas with Node.js trough Mongoose
I’m trying to connect a Node.js application with MongoDB Atlas trough Mongoose and I’m getting the following error: My code is: I’ve allowed access from every IP on mongodb atlas and when I try to connect directly to atlas everything works fine. Answer For first, you have double quotes in the connection variable. Secondly: it seems to me that mongoUri
Using async functions as conditions
Lets say i want to run an if statment where the condition is async function. This is the function, it uses mongoose findOne which is an async task. The problem is that the if statment gets called before the con can get executed which then does’nt set the condition. Answer You can do it this way : Return User.findOne from
mongoose.connect() is undefined
I’m trying to connect to my MongoDB using Mongoose and it gives me the following error. I get this Error Answer You should change 2 things: Change { mongoose } with mongoose Remove useNewUrlParser option. New version of Mongoose does not accept it as option and it will throw an error.
Destructuring a mongoose document
Using mongoose in my project, I ran into a problem. I want to find all documents that have such a key and value pair role: USER. I can get a list of documents, but I cannot get the values of specific fields from it, no matter how I try. Here is my code: The request definitely gets the document, because
(node:31873) UnhandledPromiseRejectionWarning: TypeError: Item is not a constructor
Whenever I want to make a POST request using Postman I get this error: TypeError: Item is not a constructor. Any idea why? I have my code here: And item.js: Answer You’re importing the full exports object, not just part of it. That object is not a constructor function (it’s not a function at all). Looking at your exports: According