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

  mongodb, question

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

Related codes

clipboard.png

Original data and imported data

{"_ id": {"$ oid": "58c284b13a1bb9aa7033801b"}, "productd": "201710003", "productname": "balancing car", "saleprice": 1999, "producIMAGE": "pingheng.jpg", "producurl": ""
 {"_ id": {"$ oid": "58c284d7117a2e6599abef5e"}, "productd": "20171004", "productname": "headset-3", "salesprice": 80, "producIMAGE": "2.jpg", "producurl": ""
 {"_ id": {"$ oid": "58c284e6117a2e6599abef5f"}, "productd": "20171005", "productname": "millet notebook", "saleprice": 3549, "producIMAGE": "note.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58c284f4117a2e6599abef60"}, "productd": "20171006", "productname": "millet 6", "saleprice": 2499, "producIMAGE": "mi6.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e704ef98dab115d336b3f1"}, "productd": "201710002", "productname": "smart patch panel", "saleprice": 59, "producIMAGE": "6.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e7050398 dab115d336b3f2"}, "productd": "201710007", "productname": "selfie stick", "saleprice": 39, "producIMAGE": "zipai.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e7050c98dab115d336b3f3"}, "productd": "20171008", "productname": "millet water purifier", "saleprice": 1999, "producIMAGE": "8.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e7051698dab115d336b3f4"}, "productd": "20171009", "productname": "ih rice cooker", "saleprice": 999, "producIMAGE": "9.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e7052198dab115d336b3f5"}, "productd": "20171010", "productname": "millet TV 4a", "saleprice": 2099, "producIMAGE": "10.jpg", "producURL": ""}
 {"_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": "58e7058498 dab115d336b3fc"}, "productd": "201710017", "productname": "small steel blaster bluetooth speaker", "saleprice": 129, "producIMAGE": "1.jpg", "producURL": ""}
 {"_ id": {"$ oid": "58e7058d98dab115d336b3fd"}, "productd": "201710018", "productname": "smart cameras", "saleprice": 389, "producimage": "photo.jpg", "producurl": """"}
> db.goods.find()
 {"_ id": objectid ("58c284e6117a2e6599abef5f"), "productd": "20171005", "productname": "millet notebook", "saleprice": 3549, "producIMAGE": "note.jpg", "producurl": """"}
 {"_ id": objectid ("58e7051698dab115d336b3f4"), "productd": "20171009", "productname": "ih rice cooker", "saleprice": 999, "producIMAGE": "9.jpg", "producurl": ""
 {"_ id": objectid ("58e7052198dab115d336b3f5"), "productd": "20171010", "productname": "millet TV 4a", "saleprice": 2099, "producIMAGE": "10.jpg", "producurl": ""
 { "_id" : ObjectId("58e7052a98dab115d336b3f6"), "productId" : "201710011", "productName" : "Ear1000", "salePrice" : 1000, "productImage" : "11.jpg", "productUrl" : "" }
 {"_ id": objectid ("58c284d7117a2e6599abef5e"), "productd": "20171004", "productname": "headset-3", "saleprice": 80, "producimage": "2.jpg", "producurl": ""
 { "_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": "balancing car", "saleprice": 1999, "producimage": "pingheng.jpg", "producurl": ""
 { "_id" : ObjectId("58e7057798dab115d336b3fb"), "productId" : "201710016", "productName" : "Ear700", "salePrice" : 700, "productImage" : "16.jpg", "productUrl" : "" }
 {"_ id": objectid ("58e7050c98dab115d336b3f3"), "productid": "20171008", "productname": "millet water purifier", "saleprice": 1999, "producimage": "8.jpg", "producurl": ""
 { "_id" : ObjectId("58e7054798dab115d336b3f9"), "productId" : "201710014", "productName" : "Ear1600", "salePrice" : 1600, "productImage" : "14.jpg", "productUrl" : "" }
 {"_ id": objectid ("58e7058d98dab115d336b3fd"), "productd": "20171018", "productname": "smart cameras", "saleprice": 389, "producimage": "photo.jpg", "producurl": """"}
 {"_ id": objectid ("58e7058498dab115d336b3fc"), "productd": "201710017", "productname": "small steel blaster bluetooth speaker", "saleprice": 129, "producIMAGE": "1.jpg", "producurl": ""
 {"_ id": objectid ("58e704ef98dab115d336b3f1"), "productid": "201710002", "productname": "smart patch panel", "saleprice": 59, "producimage": "6.jpg", "producurl": ""
 {"_ id": objectid ("58e705039dab115d336b3f2"), "productid": "201710007", "productname": "selfie stick", "saleprice": 39, "producimage": "zipai.jpg", "producurl": ""
 {"_ id": objectid ("58c284f4117a2e6599abef60"), "productd": "20171006", "productname": "millet 6", "saleprice": 2499, "producIMAGE": "mi6.jpg", "producurl": ""

When using the database, if you want to get what sort of order, you should specify the sort when querying. If you don’t specify the sorting criteria, the database will return the data to you in the most efficient way it thinks, without guaranteeing the order or the consistency of the order each time it comes out. Almost all databases are the same on this point.
So what is the order of your original data? Why is this order so important to you? If it is so important, then you should specify the sort, for example.sort({_id: 1})