I executed this command.
db.solarSystem.aggregate([
{
$project:{
_id:0,
name:1,
gravity:"$gravity.value",
meanTemperature:1,
density:1,
mass:"$mass.value",
radius:"$radius.value",
sma:"$sma.value"
}
}
]).pretty()
Then I got this this field order. as example.
....{
"name" : "Mars",
"meanTemperature" : -53,
"gravity" : 3.71,
"mass" : 6.4171e+23,
"radius" : 3396.2,
"sma" : 227920000
}....
then I executed this command.
db.solarSystem.aggregate([
{
$project:{
_id:0,
name:1,
gravity:1,
meanTemperature:1,
density:1,
mass:1,
radius:1,
sma:1
}
},{
$addFields:{
gravity:"$gravity.value",
mass:"$mass.value",
radius:"$radius.value",
sma:"$sma.value"
}
}
]).pretty()
Then I got this field order.
....{
"name" : "Mars",
"radius" : 3396.2,
"mass" : 6.4171e+23,
"sma" : 227920000,
"meanTemperature" : -53,
"gravity" : 3.71
}....
Why my field order has been changed ?