I am trying to connect R with Mongo using 2 packages: rmongodb and RMongo. I would like to create from R mongo query, which is based on index named id.
Id is a 19-number integer e.g 1234567891234567891, which is kept in mongo in numberlong format. Using rmongodb I don't know how to create query, which correctly understands my 19-number index e.g:
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "id", '6120367800331863610')
query <- mongo.bson.from.buffer(buf)
b <- mongo.find.one(mongo, ns=namespace, query)
or
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.long(buf, "id", 6120367800331863610)
query <- mongo.bson.from.buffer(buf)
b <- mongo.find.one(mongo, ns=namespace, query)
In the first part of code, my query looks like id : 2 6120367800331863610
Id: 2 set data type for string not for numberLong and my query produces no results.
In the second part of my code, the number that I am giving is changed by r to :
id : 18 6120367800331864064
. Id is now correct 18 represent NumberLong but number has changed. R has problem with treating such big numbers, I tried to change type for 6120367800331863610 using bit64 but type integer64 is not supported by mongo.bson.buffer.append.long()
.
My second approach to that problem was to use RMongo package. Using that I was able to get id that I was looking for but I can't use there nested keys:
dbGetQueryForKeys(mongo,namespace,"{'id':6120367800331863610}","{'id': 1, 'data.product': 1}")
Id is correct but for data.product I get null values. When I change key to {'id': 1, 'data': 1}
It gives me data.frame with ID and parse data to column, which is time consuming operation because of json-type structure of this part.
I would be grateful for any help.