My mongo collections contains documents like the following:
{
"_id" : ObjectId("52de74863fcc41ddfc7b23a5"),
"ts" : "1385969614848",
"Info" : [
{
"out" : 0,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 10,
"Type" : "1",
"Descr" : "Null",
},
{
"out" : 20000,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 70,
"Type" : "10",
"Descr" : "abc",
}
]
}
{
"_id" : ObjectId("52de74863fcc41ddfc7b23a6"),
"ts" : "1385969614852",
"Info" : [
{
"out" : 500,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 100,
"Type" : "1",
"Descr" : "Null",
},
{
"out" : 2896,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 4052,
"Type" : "10",
"Descr" : "abc",
}
]
}
I want to sort on key "out". In order to do that, I wrote the following mongo query:
db.collection_name.find({},{"Info.out":1}).sort({"Info.out":1}).pretty()
then it shows following output:
{
"_id" : ObjectId("52fa2922d73ddc832323f402"),
"Info" : [
{
"out" : 0
},
{
"out" : 10
},
{
"out" : 20000
},
{
"out" : 70
}
]
}
{
"_id" : ObjectId("52fa292ed73ddc832323f403"),
"Info" : [
{
"out" : 500
},
{
"out" : 100
},
{
"out" : 2896
},
{
"out" : 4052
}
]
}
But, I expected the output below:
{
"_id" : ObjectId("52fa2922d73ddc832323f402"),
"Info" : [
{
"out" : 20000
},
{
"out" : 70
},
{
"out" : 10
},
{
"out" : 0
}
]
}
{
"_id" : ObjectId("52fa292ed73ddc832323f403"),
"Info" : [
{
"out" : 4052
},
{
"out" : 2896
},
{
"out" : 500
},
{
"out" : 100
}
]
}
Does anyone know how to reach the desired output?