Download - All IT eBooks

Transcript
Managing the Data
The query db.ordersQueue.find() produces the following result:
{
"_id" : ObjectId("54d97db16840a9a7c089fa30"),
"orderId" : "order_1",
"time" : 1423539633910
}
{
"_id" : ObjectId("54d97db66840a9a7c089fa31"),
"orderId" : "order_2",
"time" : 1423539638006
}
{
"_id" : ObjectId("54d97dba6840a9a7c089fa32"),
"orderId" : "order_3",
"time" : 1423539642022
}
{
"_id" : ObjectId("54d97dbe6840a9a7c089fa33"),
"orderId" : "order_4",
"time" : 1423539646015
}
{
"_id" : ObjectId("54d97dcf6840a9a7c089fa34"),
"orderId" : "order_5",
"time" : 1423539663559
}
If we use the $natural operator as shown in the following query, we will have the
same result as shown in the preceding output:
db.ordersQueue.find().sort({$natural: 1})
But if we need the last insertion first, we must execute the command with a -1 value
on the $natural operator:
db.ordersQueue.find().sort({$natural: -1})
[ 122 ]