-1

パッケージhintを使用するときにmongoクエリに引数を追加する方法を知っている人はいますか? rmongodb注:hint現在は廃止されています。

現在、個別の ,コマンドmongo.find.allではなく、単純さのためにクエリを使用しています。cursorbuffer

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)

mongo では、上記の完全な例のすべてのフィールドを除いて、クエリは次のようになります。

db.weather.find({"where.zip_code" : "60603","what.currently.time" : {"$gte" : 1430936418}}).hint("where.zip_code_1_what.currently.time_1")

このヒントは、Mongo で使用するとクエリのパフォーマンスが明らかに向上するため、進行中の R プロセスに実装すると便利です。

現在のセッション情報()

> 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 a 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 
4

1 に答える 1

1

少し調べたところ、ヒントを $hint 引数としてクエリに指定できることがわかりました。mongodb では、次のようになります。

db.weather.find( {$query: {...}, $hint: {"where": 1, ...}})

rmongodb でも同じことができます。クエリを次のように変更します。

query = 
  "{\"$query\":
     {\"where.zip_code\":\"60603\", \"what.currently.time\":{\"$gte\":1430936418}},
    \"$hint\":
      \"where.zip_code_1_what.currently.time_1\"}"

これをテストしたところ、テスト データセットでエラーなく動作しました。これがうまくいったかどうか教えてください。

于 2015-09-06T12:26:36.883 に答える