I have these documents in a mongoDB:
/* 1 */
{
"_id" : ObjectId("553ce99a39108e2b7c1edeb9"),
"coleccion" : "aplicaciones",
"nombre" : "Mascotas",
"descripcion" : "Censo de mascotas",
"tipo" : "privada"
}
/* 2 */
{
"_id" : ObjectId("553e316e39108e802a1edeb9"),
"coleccion" : "aplicaciones",
"nombre" : "otra aplicacionn",
"descripcion" : "w aplicacion",
"tipo" : "privada",
"campoId" : [
{
"id" : "1430145364",
"id_campo" : "553bffca39108eb163cff7aa",
"orden" : 90
},
{
"id" : "1430145368",
"id_campo" : "553bffed39108e346ccff7ab",
"orden" : 100,
"estado" : "0"
},
{
"id" : "1430145370",
"id_campo" : "553c001139108ebc63cff7aa",
"orden" : 29,
"estado" : "1"
},
{
"id" : "1430145395",
"id_campo" : "553c001139108ebc63cff7aa",
"orden" : 9,
"estado" : "0"
}
]
}
I need to query and sort the data in ascending order of each document using the field " campoId.orden " and have executed this query:
db.getCollection('aplicaciones').find({}).sort({'campoId.orden' : -1})
but I do not get the order I want. can anyone suggest me a way?