Search code examples
rmongodbrmongo

Return strings as strings instead of integers in RMongo?


I run the following Query in RMongo:

> test <- dbGetQuery(db,'mycollection', '{"zip" : "06840"}', skip=0,limit=1e10)
> test
      update  zip 
1 2013-03-11 6840 

The item is stored in MongoDB, with leading zeros, as a string, and RMongo is able to search for it that way.

But the RMongo return object in R is converting it to an integer. I looked through the RMongo help and couldn't find a "don't coerce numbers to different type" flag.

Any solution to keep my data a string and avoid losing my leading zeros? Zip codes are a classic offender here, and a very common use-case.


Solution

  • As of November 5, 2013, this is a bug in the RMongo package and it is not currently possible to get around it.