T
T
Timokins2017-03-09 04:37:37
MongoDB
Timokins, 2017-03-09 04:37:37

Is it possible to exclude the results of one query in another?

Hello,
is there any option in mongodb to exclude the results of one query in another?
For example, there are two collections,
1. General list of tasks
2. List of completed tasks of all users
First, you need to select the list of completed tasks for a specific user,
and then the general list of tasks, excluding the result of the first query from it.
As far as I know JOIN is missing from mongo and lookup works a bit differently.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kliss, 2017-03-20
@timokins

Got a list of tasks from the first request. You make a second request, where you do

db.tasks.find( { id: { $nin: task_ids_from_first_query } } )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question