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: mongodb
Login function : Error [ERR_HTTP_HEADERS_SENT]
enter image description here I’m trying to login as a user on my website and it’s giving me this error, I can register the user and search for it in the login as many times as I want if the password and username are correct, however when there is an error in the user name or password it happens this
Finding data from one array by looping another array (MongoDB, Javascript)
I have 2 arrays. I want to get an array of objects with same id. Like when I go get all the object of 1 then I will loop through array2 and get the object then put them in a 3rd array. I’m stuck at this point. Update: Thanks to flyingfox for solving my issue. But I see that if
When formatting date object – does it matter that the T and the 000Z will be removed when storing to db?
Sorry if its a very basic question but I dont understand the following: When I format the Date object (no matter what library I used), I get a string. Even if I turn it back into an object it, the T and 000Z will never be there anymore. Do I just ignore that (seems like it as any library or
Creating a field in an a object if it doesn’t exist, incrementing it if it does if it does, for multiple objects?
I have a collection “users” There’s a notifications field that has an object. Every field of this object corresponds to a chat channel ID and they value is the amount of notifications in the channel (unread messages). If user “u101” and “u102” are both in the the same channel and they recieve a notification, I’d need to create a “channelId”
mongodb .find elements in an array
I have an array that dynamically holds document id’s, in which I need to query another collcetion in mongo to see if the id’s match. I have this code: however, doing “id”: { $in: array_of_docs_bought } doesn’t iterate through the array, so it returns nothing, but when I do this: let documents = await database.collection(‘documents’).find({ “id”: { $in: [ ‘g81h8’,
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
getting a weird error while trying to connect the app.js with mongodb
I’ve installed MongoDB and the compass as well and everything works just fine, when I try to connect mongo with my app.js I get a weird error. Could any of you tell me what the error means and what can I? Sorry about the links to the images, not allowed to embed images yet.. Thanks in advance Error enter image
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