DB Sample...
{ "code" : "2156",
"trades" : [
{
"close" : 78000,
"date" : "2017.11.08"
},
{
"close" : 25300,
"date" : "2017.08.07"
},
{
"close" : 74900,
"date" : "2017.11.07"
}
]
},
{ "code" : "2158",
"trades" : [
{
"close" : 79000,
"date" : "2017.11.08"
},
{
"close" : 24300,
"date" : "2017.08.07"
},
{
"close" : 71900,
"date" : "2017.11.07"
}
]
}
Above is my exist mongodb data sample. What I want to do is arrange objects in trades
by date asc. So It should be arrange like this
"trades" : [
{
"close" : 24300,
"date" : "2017.08.07"
},
{
"close" : 71900,
"date" : "2017.11.07"
},
{
"close" : 79000,
"date" : "2017.11.08"
}
]
Is there any way to do this? I'm using Node.js and Mongoose. I already check this article :
how to sort array inside collection record in mongoDB
But it looks like not ordering db itself, it just query db to certain conditions, right? Is there a way to ordering db itself?