J
J
JavaSscriptNoob2022-02-04 13:18:23
MongoDB
JavaSscriptNoob, 2022-02-04 13:18:23

How to create data for a specific user node js ( express )?

Hello everyone, I wanted to know the logic of creating a conditional task (task) for a specific user, where the task is an object that lies in the tasks collection.
It is necessary for me that at each user with unique. _id was some kind of list of tasks ( tasks ) that will be tied to this particular user. From ideas: each user will have un. _id , there is an idea to assign this _id to each task created by this particular user.
Will such an idea work? And what is the right way to do it? Thank you . I use : MondoDB , mongoose , express , node.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rag'n' Code Man, 2022-02-04
@JavaSscriptNoob

At the task, we create the owner_id field and put the user id there.
And when we get a user, we do

$lookup: {
   from: 'Tasks',
   as: 'tasks',
   localField: '_id',
   foreignField: 'owner_id'
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question