Pergunta

Hi and thanks in advance for helping out. I was not able to find this question or solution on a different post, please let me know if I missed it.

My problem is that I am seeing a few field's $type value change after being exported and imported into another collection. I have data in a collection in Environment A, which I want to export and import to a different Environment B. While looking at the source data in environment A, all types of the field are correctly a 64-bit integer ($type 18 - from the docs). However, once the data is imported into Environment B 5 of the 720 docs have a $type of 16 (32-bit integer).

Output from Environment A:

mongos> db.myCollection.count()    
720
mongos> db.myCollection.count({createTime : {$type : 16}})
0
mongos> db.myCollection.count({createTime : {$type : 18}})
720

Data was exported from Environment A with an equivalent command: mongoexport --host my.environment.a.host.com -d myDb -c myCollection -o outputFile.json

Data was imported to Environment B with an equivalent command: mongoimport --host my.environment.b.host.com -d myDb -c myCollection --file outputFile.json

Looking at the data in Environment B, i see the following count/types:

db.plaAdGroupDoc.count()
0
db.productDoc.count({createTime : {$type : 16}})
5
db.productDoc.count({createTime : {$type : 18}})
715
db.productDoc.count()
720

I am unclear as to why the types of the field have changed from the import. Moreover, why only a small portion of the fields have changed. Any insight would be greatly appreciated.

Thanks!

Edit: Resolved (unable to answer question within 8 hours) Looking more at this, it seems that the 5 entires that were imported as a 32-bit integer ($type 16) had values of 0, rather than large values. This seems to be the reason why they have defaulted to ints instead of 64-bit integers. Question resolved.

Hope this helps someone else!

Foi útil?

Solução

You should not be using mongoexport and import if you are moving data between two mongoDB instances. Those tools are intended for exchange of data with external systems.

Use mongodump and mongorestore instead - they use bson which is MongoDB's native format and they preserve all types.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top