dselivanov / rmongodb

R driver for MongoDB
53 stars 26 forks source link

Cannot retrieve data when $in is used #63

Closed gousiosg closed 9 years ago

gousiosg commented 9 years ago

I am trying to run a query that looks like this in JSON format:

{
    "projectId": "d84b99a1123ccc6052807f81c019f17cb61151bf",
    "it": {
        "$in": [
            "ea",
            "eo"
        ]
    }
}

In the MongoDB command line, this returns some rows:

> use test
> db.intervals.find({"projectId" : "d84b99a1123ccc6052807f81c019f17cb61151bf", "it":{"$in":["ea", "eo"]}}).count()
1825

However, when I try exactly the same query in R with rmongodb, I get -1 as a result:

> mongo.count(conn, "test.intervals", mongo.bson.from.JSON('{"projectId" : "d84b99a1123ccc6052807f81c019f17cb61151bf", "it":{"$in":["ea", "eo"]}}'))
[1] -1

This behavior is the same in the version of rmongodb that is currently on CRAN (1.6.5) and also the latest master ea900ccbde.

dselivanov commented 9 years ago

Please provide sessionInfo(). I expect you use 1.6.5 version of rmongodb in both cases. I have no issues with latest github version on similar examples.

gousiosg commented 9 years ago

Here is the result of running sessionInfo()

R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] el_GR.UTF-8/el_GR.UTF-8/el_GR.UTF-8/C/el_GR.UTF-8/el_GR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmongodb_1.7.3

loaded via a namespace (and not attached):
[1] jsonlite_0.9.12 plyr_1.8.1      Rcpp_0.11.2     tools_3.1.0    
> 

In the current session, I am using the latest master version. The behavior is exactly the same in version 1.6.5.

dselivanov commented 9 years ago

Does this code work?

library(rmongodb)
mongo <- mongo.create()
for (lt in letters[1:5])
  mongo.insert(mongo, 'test.test', b = list(projectId = "d84b99a1123ccc6052807f81c019f17cb61151bf", it = lt))
mongo.insert(mongo, 'test.test', b = list(projectId = "falseid", it = lt))
mongo.count(mongo, 'test.test', query = mongo.bson.from.JSON('{"projectId" : "d84b99a1123ccc6052807f81c019f17cb61151bf", "it":{"$in":["a", "b"]}}'))
mongo.drop(mongo, ns = 'test.test')
mongo.destroy(mongo)
dselivanov commented 9 years ago

@gousiosg , did you resolve this issue?

dselivanov commented 9 years ago

Assume issue resolved, I didn't recieve any feedback or comment. Close this. If the issue is still not resolved, please provide fully reproducible example.