Skip to content
Advertisement

How to query on collection values ​and referenced documents values ​in MongoDB?

I don’t know how correctly I formulated the question. I need to execute a query on both the values ​​of the collection and the values ​​of the referenced objects.

The original collection looks like this:

JavaScript

When executing a query that meets the condition district == "Texas", I need to get the following result:

JavaScript

Under this condition: kind == "developer", get the following result:

JavaScript

And for a query that satisfies the condition: district == "Texas" && kind == "developer", get the result:

JavaScript

The query should be executed using mongoose inside the express route, and should be universal, processing a different set of request parameters:

JavaScript

The House model refs to Event:

JavaScript

I am learning MongoDB and aggregation, but I don’t know so deeply all its functions. Please tell me how to correctly execute such a request in the traditional way? I will be very grateful!

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement