I’m building a taskmanagment application, where only admin can delete user. when admin delete a user, I want to assign deleted users task to the his assignby user. when I delete devid user from the db I want to assign his task to the john and save the task Answer I think you are looking for transactions to avoid loss
Tag: mongoose
Populate field then find – mongoose
I have a Cheques and a Payees collection, every cheque has its corresponding Payee ID. What I’m trying to do is to write some queries on cheques, but I need to preform the searching after populating the payee (to get the name) I guess what I’m trying do is fit this somewhere in my code, I have tried to put
Mongoose how to extract value from findOne() and use that to update value
And the console log shows flightNo as { flightNo: ‘UA567’ } I want to use the flightNo “UA567” in findOneAndUpdate. But this function fails. How can I extract the string from the object? Answer flightNo is an object which contains the field ‘flightNo’, you can access the value of that field by writing or you can write and destructure that
How to query based on a field in a referenced document in mongodb
I have two MongoDB collections. First is Products, and the seconds is Users. The product documents has a field ownerId which refers to the users collection and the user has a Boolean field isActive. What I want to do is to find all the products where their users are active using Mongoose method collection.find(). I don’t know if i can
Mongo Organize by object inside aggregate request
My project is in nodeJs with express and i use mongoose for the request to my database mongoDb. I have a model Media the structure is: Like you seen there is a field date, imagine that i have 3 medias on differents month: I want to output something like this: Is found the property aggregate but i don’t understand it
Can anyone know if we can tag the MongoDB queries/commands to know which function of the app ran that query/command?
I am using the same query (or slightly modified but using the same MongoDB Collection) in various functions and on Mongo Atlas, we get only the collection name and query but don’t know which function actually triggered it. Is there any way to tag the queries with the functions so it can be easy to debug? Answer Two things come
TypeError Option “role” is of type 8; expected 3
So I am making a role add and role remove command using slash command options. I have saved an argument called role which takes from the slash command option addRoleOption. Upon running the slash command and pointing in the role I am trying to add / remove from the user I have mentioned i get the error as shown below.
Unable to select certain fields in MongoDB (Mongoose) result
I’ve ran into a bit of an odd issue with a mongoose result. I can select one value from the object, but not another. For example I’m calling I get a result and im console logging out the entire product. The result is: I can log out the storePrice field However if I try to log out the dropDate and
Req.params and req.user missing after hitting stripe checkout flow
I’m trying to integrate Stripe subscriptions billing in my app with a tiered pricing model and based on my understanding, I need to do two things: Allow my new users to also create a stripe customer account (via the integration) Monitor Stripe webhook ‘events’ to provision access while customer subscription payments are active My userflow is as follows: create profile
Undefined when searching with Find Mongoose Express
I receive an array of products that I need to search for with Mongoose, so I use Find passing the _id of each product. But when going through the array and trying to search, I only receive the data of the first product, for the others I always receive undefined. This is my code: In my MongoDB database I have