-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 回答