r - Add a $hint to rmongodb query -
does know how add hint
argument mongo query when using rmongodb
package? note: hint
deprecated.
currently i'm using mongo.find.all
query it's simplicity rather separate cursor
, buffer
commands.
mongo.find.all(mongo = mongo, ns = "ops.weather", query = "{\"where.zip_code\":\"60603\", \"what.currently.time\":{\"$gte\":1430936418}}", sort = mongo.bson.empty(), fields = list(what.currently.time = 1l, what.currently.precipintensity = 1l, what.currently.temperature = 1l, what.currently.windspeed = 1l, what.currently.windbearing = 1l, where.zip_code = 1l, where.latitude = 1l, where.longitude = 1l, what.observation_type = 1l), limit = 0l, skip = 0l, options = 0l, data.frame = true)
in mongo query this, without fields in full example above:
db.weather.find({"where.zip_code" : "60603","what.currently.time" : {"$gte" : 1430936418}}).hint("where.zip_code_1_what.currently.time_1")
the hint improves query performance when used in mongo, useful implement in ongoing r process.
current sessioninfo()
> sessioninfo() r version 3.2.1 (2015-06-18) platform: i386-w64-mingw32/i386 (32-bit) running under: windows 7 (build 7601) service pack 1 locale: [1] lc_collate=english_united states.1252 lc_ctype=english_united states.1252 [3] lc_monetary=english_united states.1252 lc_numeric=c [5] lc_time=english_united states.1252 attached base packages: [1] stats graphics grdevices utils datasets methods base other attached packages: [1] rmongodb_1.8.0 loaded via namespace (and not attached): [1] plyr_1.8.3 tools_3.2.1 rstudioapi_0.3.1 rcpp_0.12.0 jsonlite_0.9.16
after doing bit of research, found can supply hint $hint argument query. in mongodb this:
db.weather.find( {$query: {...}, $hint: {"where": 1, ...}})
and can same in rmongodb. change query this:
query = "{\"$query\": {\"where.zip_code\":\"60603\", \"what.currently.time\":{\"$gte\":1430936418}}, \"$hint\": \"where.zip_code_1_what.currently.time_1\"}"
i tested , worked on test dataset without errors. let me know if worked you.
Comments
Post a Comment