Here is the document:
{
"_id":1,
"CID":"1",
"a" : "Z",
"b" : "Y",
"sign": [{
"c": "c",
"d": "d",
"e": "e",
"f": "insufficientFunds"
}, {
"g": false,
"h": null,
"i": 0,
"j": "accessFunds"
}],
"y": null,
"z": true
}
Required Output:
/* 1 */
{
"_id" : 1.0,
"CID" : "1",
"c" : "c",
"d" : "d",
"e" : "e",
"f" : "insufficientFunds",
"g" : null,
"h" : null,
"i" : null,
"j" : null
}
/* 2 */
{
"_id" : 1.0,
"CID" : "1",
"c" : null,
"d" : null,
"e" : null,
"f" : null,
"g" : false,
"h" : null,
"i" : 0.0,
"j" : "accessFunds"
}
Here is the query
db.myColl.aggregate( [
{
"$match" : {
"_id" : 1
}
},
{ $unwind: "$sign" },
{ $replaceRoot: { newRoot: "$sign" }},
{
"$project" : {
"CID":1,
"a" : 1,
"b" : 1,
"y": 1,
"z": 1,
"c": 1,
"d": 1,
"e": 1,
"f": 1,
"g": 1,
"h": 1,
"i": 1,
"j": 1
}
}
])
Output from the above query
/* 1 */
{
"c" : "c",
"d" : "d",
"e" : "e",
"f" : "insufficientFunds"
}
/* 2 */
{
"g" : false,
"h" : null,
"i" : 0.0,
"j" : "accessFunds"
}