Pymongo Querying a second collection based on the ObjectId that is linked in the first collection

Viewed 31

I am using pymongo and I have a collection lets call it "districts" I have some basic information about the district in the document. I Also have a referenced ObjectId for a "district_admin" which is located in a second collection called "district_admins". I'm to query all the districts and also have the object of that district admin included in that single query. What is my best appoach?

District Collection:

_id:ObjectId("jn2783h42837bd823sadf")
district_name:"Example District"
district_address:"123 Example Way"
district_admin:ObjectId("923874y32kjnkjnkjn")

District_admin Collection

_id:ObjectId("923874y32kjnkjnkjn")
first_name:"John"
last_name:"wayne"
1 Answers

It seems like you are looking for the $lookup operator.
-– @styvane

Related