Home > database >  Mongo alias set
Mongo alias set

Time:09-23

Mongo data in the database
 {
"_id" : ObjectId (" 5 c88c7d72db68f5597065063 "),
"Array" : [
{
"A" : "a1",
"B" : {
"C" : "c1"
}
},
{
"A" : "a2",
"B" : {
"C" : "c2"
}
}
]
}


I want to take out from the mongo data format for (remove the b this layer) :
 {
"_id" : ObjectId (" 5 c88c7d72db68f5597065063 "),
"Array" : [
{
"A" : "a1",
"C" : "c1"
},
{
"A" : "a2",
"C" : "c2"
}
]
}


I use the query:
 the test_alias. Aggregate ({" $project ": {" array. A" : 1, "array. C" : "$array. The biggest"}}) 


Results:
 {
"_id" : ObjectId (" 5 c88c7d72db68f5597065063 "),
"Array" : [
{
"A" : "a1",
"C" : [
"C1",
"C2"
]
},
{
"A" : "a2",
"C" : [
"C1",
"C2"
]
}
]
}



Such as how to get, please I hope the data format
  • Related