I have the following situation:
collection
departments:{ "_id" : 0, "name" : "Dep_A_1", "description" : "Department A1" } { "_id" : 1, "name" : "Dep_B_1", "description" : "Department B1" } { "_id" : 2, "name" : "Dep_C_1", "description" : "Department C1" }collection
skills:{ "_id" : 0, "name" : "Creativity", "description" : "description", "type" : "soft", "categories" : [ 0, 2 ] }collection
roles:{ "_id" : 0, "name" : "Software Developer Automation and Control", "description" : "Automation and Control expert", "departments" : [ 0, 2 ], "skills" : [ { "_id" : 18, "weight" : 30 } ] }
I need a result like this:
{
"_id" : 0,
"name" : "Software Developer Automation and Control",
"description" : "Automation and Control expert",
"departments" : [
{
"_id" : 0,
"name" : "Dep_A_1",
"description" : "Department A1"
},
{
"_id" : 2,
"name" : "Dep_C_1",
"description" : "Department C1"
}
],
"skills" : [
{
"_id" : 0,
"name" : "Creativity",
"description" : "description",
"type" : "soft",
"weight" : 30
}
]
}
I need to replace the role.departments and role.skills arrays with the respective object in the departments and roles collection. Is there a way to query Mongo and get a result like this?
Anyway I am using Mongo 3.6 and Pymongo. Thanks.