If through mongo shell is used the following (for few documents 50 for example)
db.<collection>.insertMany(
[
{
"name": "some name 1",
...
},
{
"name": "some name 2",
...
},
...
{
"name": "some name N",
...
}
])
I can confirm that through db.<collection_name>.find()
the documents are shown in the exact same order how they were declared and inserted through db.<collection>.insertMany()
. Until here it is expected and is fine for me.
I did realize the following, if the collection is empty, and if the same content shown above - keeping the same the order - is declared as follows within the import.js
file for importation purposes:
[
{
"name": "some name 1",
...
},
{
"name": "some name 2",
...
},
...
{
"name": "some name N",
...
}
]
Therefore, is used the same content and order but db.<collection>.insertMany()
was removed/ignored.
So, then if is executed through the console/terminal the following command:
mongoimport --db some_db \
--collection collection_name \
--file /path/import.json \
--jsonArray
I can confirm the importation process is accomplished but if db.<collection_name>.find()
is executed then the documents are shown in a different order how they were declared and inserted through db.<collection>.insertMany()
as the first approach.
How fix this? It is problematic for aggregations how $first
and $last