MongoDB collection uses mongoimport import json, imported data order is inconsistent with the original data order

use mongoimport to import data in json format. After the import is successful, the data in the collection is in the wrong order, and the cause of the problem has not been found.

related codes

clipboard.png

original data and imported data

{"_id":{"$oid":"58c284b13a1bb9aa7033801b"},"productId":"201710003","productName":"","salePrice":1999,"productImage":"pingheng.jpg","productUrl":""}
{"_id":{"$oid":"58c284d7117a2e6599abef5e"},"productId":"201710004","productName":"-3","salePrice":80,"productImage":"2.jpg","productUrl":""}
{"_id":{"$oid":"58c284e6117a2e6599abef5f"},"productId":"201710005","productName":"","salePrice":3549,"productImage":"note.jpg","productUrl":""}
{"_id":{"$oid":"58c284f4117a2e6599abef60"},"productId":"201710006","productName":"6","salePrice":2499,"productImage":"mi6.jpg","productUrl":""}
{"_id":{"$oid":"58e704ef98dab115d336b3f1"},"productId":"201710002","productName":"","salePrice":59,"productImage":"6.jpg","productUrl":""}
{"_id":{"$oid":"58e7050398dab115d336b3f2"},"productId":"201710007","productName":"","salePrice":39,"productImage":"zipai.jpg","productUrl":""}
{"_id":{"$oid":"58e7050c98dab115d336b3f3"},"productId":"201710008","productName":"","salePrice":1999,"productImage":"8.jpg","productUrl":""}
{"_id":{"$oid":"58e7051698dab115d336b3f4"},"productId":"201710009","productName":"IH ","salePrice":999,"productImage":"9.jpg","productUrl":""}
{"_id":{"$oid":"58e7052198dab115d336b3f5"},"productId":"201710010","productName":"4A","salePrice":2099,"productImage":"10.jpg","productUrl":""}
{"_id":{"$oid":"58e7052a98dab115d336b3f6"},"productId":"201710011","productName":"Ear1000","salePrice":1000,"productImage":"11.jpg","productUrl":""}
{"_id":{"$oid":"58e7053298dab115d336b3f7"},"productId":"201710012","productName":"Ear1100","salePrice":1100,"productImage":"12.jpg","productUrl":""}
{"_id":{"$oid":"58e7053c98dab115d336b3f8"},"productId":"201710013","productName":"Ear2000","salePrice":2000,"productImage":"13.jpg","productUrl":""}
{"_id":{"$oid":"58e7054798dab115d336b3f9"},"productId":"201710014","productName":"Ear1600","salePrice":1600,"productImage":"14.jpg","productUrl":""}
{"_id":{"$oid":"58e7055198dab115d336b3fa"},"productId":"201710015","productName":"Ear1200","salePrice":1200,"productImage":"15.jpg","productUrl":""}
{"_id":{"$oid":"58e7057798dab115d336b3fb"},"productId":"201710016","productName":"Ear700","salePrice":700,"productImage":"16.jpg","productUrl":""}
{"_id":{"$oid":"58e7058498dab115d336b3fc"},"productId":"201710017","productName":"","salePrice":129,"productImage":"1.jpg","productUrl":""}
{"_id":{"$oid":"58e7058d98dab115d336b3fd"},"productId":"201710018","productName":"","salePrice":389,"productImage":"photo.jpg","productUrl":""}
> db.goods.find()
{ "_id" : ObjectId("58c284e6117a2e6599abef5f"), "productId" : "201710005", "productName" : "", "salePrice" : 3549, "productImage" : "note.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7051698dab115d336b3f4"), "productId" : "201710009", "productName" : "IH ", "salePrice" : 999, "productImage" : "9.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7052198dab115d336b3f5"), "productId" : "201710010", "productName" : "4A", "salePrice" : 2099, "productImage" : "10.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7052a98dab115d336b3f6"), "productId" : "201710011", "productName" : "Ear1000", "salePrice" : 1000, "productImage" : "11.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58c284d7117a2e6599abef5e"), "productId" : "201710004", "productName" : "-3", "salePrice" : 80, "productImage" : "2.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7053298dab115d336b3f7"), "productId" : "201710012", "productName" : "Ear1100", "salePrice" : 1100, "productImage" : "12.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7053c98dab115d336b3f8"), "productId" : "201710013", "productName" : "Ear2000", "salePrice" : 2000, "productImage" : "13.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7055198dab115d336b3fa"), "productId" : "201710015", "productName" : "Ear1200", "salePrice" : 1200, "productImage" : "15.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58c284b13a1bb9aa7033801b"), "productId" : "201710003", "productName" : "", "salePrice" : 1999, "productImage" : "pingheng.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7057798dab115d336b3fb"), "productId" : "201710016", "productName" : "Ear700", "salePrice" : 700, "productImage" : "16.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7050c98dab115d336b3f3"), "productId" : "201710008", "productName" : "", "salePrice" : 1999, "productImage" : "8.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7054798dab115d336b3f9"), "productId" : "201710014", "productName" : "Ear1600", "salePrice" : 1600, "productImage" : "14.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7058d98dab115d336b3fd"), "productId" : "201710018", "productName" : "", "salePrice" : 389, "productImage" : "photo.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7058498dab115d336b3fc"), "productId" : "201710017", "productName" : "", "salePrice" : 129, "productImage" : "1.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e704ef98dab115d336b3f1"), "productId" : "201710002", "productName" : "", "salePrice" : 59, "productImage" : "6.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58e7050398dab115d336b3f2"), "productId" : "201710007", "productName" : "", "salePrice" : 39, "productImage" : "zipai.jpg", "productUrl" : "" }
{ "_id" : ObjectId("58c284f4117a2e6599abef60"), "productId" : "201710006", "productName" : "6", "salePrice" : 2499, "productImage" : "mi6.jpg", "productUrl" : "" }
Jun.23,2021

when using the database, if you want to get what kind of order, you should specify the sort when querying. If you do not specify sorting conditions, the database will return the data to you in the most efficient way it thinks, without guaranteeing the order or the order that comes out each time. At this point, almost all databases are the same.
so what is the order of your original data? Why is this order so important to you? If it's so important, you should specify a sort, such as .sort ({_ id: 1})

.
Menu