Closed defoo closed 13 years ago
Hi,
I am trying to query my mongodb with a regex query such as the one below:
mongo <- mongoDbConnect("test_database") output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}') dbGetQuery(mongo, 'test_data', '{"foo": "/bar/i"}')
However, RMongo seems to treat it as a simple string matching, and returns nothing: data frame with 0 columns and 0 rows
I then tried another way to specify the regex:
dbGetQuery(mongo, 'test_data', '{"foo": { "$regex" :"/bar/i" } }')
And this time, the following is returned:
Error in .jcall(rmongo.object@javaMongo, "S", "dbGetQuery", collection, : java.lang.NullPointerException
I am wondering if there is a way to specify regex in RMongo?
Thanks, Derek
Try this mongodb regex convention: {"foo": {"$regex": "bar", "$options": "i"}}
see http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON for more details.
Thanks. This works perfectly!
Hi,
I am trying to query my mongodb with a regex query such as the one below:
mongo <- mongoDbConnect("test_database") output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}') dbGetQuery(mongo, 'test_data', '{"foo": "/bar/i"}')
However, RMongo seems to treat it as a simple string matching, and returns nothing: data frame with 0 columns and 0 rows
I then tried another way to specify the regex:
dbGetQuery(mongo, 'test_data', '{"foo": { "$regex" :"/bar/i" } }')
And this time, the following is returned:
Error in .jcall(rmongo.object@javaMongo, "S", "dbGetQuery", collection, : java.lang.NullPointerException
I am wondering if there is a way to specify regex in RMongo?
Thanks, Derek