I have the following documents, few documents only have bids
fields.
Collection:
{
"_id" : "PqwSsLb2jsqTycMWR",
"name" : "aaa",
"bids" : [
{
"amount" : NumberInt(450)
}
]
}
{
"_id" : "93EDoQfeYEFk8pyzX",
"name" : "bbb"
}
{
"_id" : "j5wkK5Eagnwuo8Jym",
"name" : "ccc",
"bids" : [
{
"amount" : NumberInt(520)
}
]
}
{
"_id" : "eLaTyM5h5kqA97WQQ",
"name" : "ddd"
}
If I sort with bids.amount : 1
am getting below results
Result:
{
"_id" : "93EDoQfeYEFk8pyzX",
"name" : "bbb"
}
{
"_id" : "eLaTyM5h5kqA97WQQ",
"name" : "ddd"
}
{
"_id" : "PqwSsLb2jsqTycMWR",
"name" : "aaa",
"bids" : [
{
"amount" : NumberInt(450)
}
]
}
{
"_id" : "j5wkK5Eagnwuo8Jym",
"name" : "ccc",
"bids" : [
{
"amount" : NumberInt(520)
}
]
}
But I want to re arrange the order where bid.amount
should comes at top.
Expected result:
{
"_id" : "PqwSsLb2jsqTycMWR",
"name" : "aaa",
"bids" : [
{
"amount" : NumberInt(450)
}
]
}
{
"_id" : "j5wkK5Eagnwuo8Jym",
"name" : "ccc",
"bids" : [
{
"amount" : NumberInt(520)
}
]
}
{
"_id" : "93EDoQfeYEFk8pyzX",
"name" : "bbb"
}
{
"_id" : "eLaTyM5h5kqA97WQQ",
"name" : "ddd"
}
Whats the query to get expected result?