I am trying to migrate data’s from MySql to MongoDb. While migrating the Id’s from MySql which is integer like 1 or 2 or 3 etc., which i am trying to save as old_id in mongo. But while saving in to mongo it is taking double quotes means converting to string. I tried (int) while inserting to mongo document, then it is saving as NumberLong(2). How can i save only integer number to mongo document??
As far as I can remember, MongoDB-Documents are plain JSON-objects and if this true, there can be no integers stored, as JSON does not know about them.
I think it’s possible to store numbers as integer types in mongo if the number doesn’t have a decimal part.
I’ve googled a bit and in fact it seems as if unannotated numbers are treated floats and if one wants to store integers one has to use
NumberInt or other integer types, well or serialize into a string manually.
Are you using Elixir for this? What version of Mongo are you using?
MongoDB version v3.4.14
So it seems to me that
NumberLong(2) is the default, and
NumberInt(2) might be what you want.