E
E
Eugene2017-11-05 00:22:00
JavaScript
Eugene, 2017-11-05 00:22:00

How to fetch from MongoDB?

Hello! The question arose, rather from an insufficient understanding of how to make a selection from the database.
For example, we have the following collections:
Users: {_id, name, password, email}
Teams: {_id, name, team_leader, team_members: []}
Clients: {_id, name, team_id, profile: [], users_access: []}
Tasks: {_id, task, team_id, user_creator_id, access_users: []}
I don't understand at all how to select clients and tasks for a team member if he has access (users_acces).
In my understanding:

  1. Get team id by user id
  2. We make a selection from clients or tasks by user ID and team ID

The only question is how to do it?
Or did I design the base incorrectly?
How do I generally switch from MySQL to MongoDB?
Yes, I understand that it's easier to take MySQL and not worry. But the next project is planned for MeteorJS and only Mongo here.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yura Zubarev, 2018-08-16
@zentelechia

Sampling works fine in mongo

Clients.find({ users_access: this.userId})
Tasks.find({access_users: this.userId}
)
Despite the fact that access_users is an array of user IDs, { access_users: id } allows you to select those documents where the value is included in the array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question