Skip to content
Advertisement

Tag: mongoose

Couldn’t generate jwt token with a nodejs sign-in

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

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

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

Advertisement