我正在使用的 Mongo 数据库集合的项目有一个字段“UID”。我想查找 UID 等于 1、2 或 5 的所有项目。
这是 MongoVUE 查询:
{"UID":{"$in":[1, 2, 5]}}
这行得通。
这是中的查询rmongodb
:
cursor <- mongo.find(mongo, ns,
query = list(UID = list('$in' = c(1,2,5))))
dummy <- mongo.cursor.next(cursor)
db.value <- mongo.cursor.value(cursor)
db.value
# NULL
另一个尝试:
cursor <- mongo.find(mongo, ns,
query = '{"UID":{"$in":[1,2,5]}}')
结果相同。但是,如果我尝试仅获取一项:
cursor <- mongo.find(mongo, ns,
query = list(UID = 1))
有用。
知道出了什么问题吗?
更新:
我发现以下确实有效:
cursor <- mongo.find(mongo, ns,
query = list(UID = list('$in' = c(1,2,5))))
但仅当向量具有多个元素时。我使用单元素向量进行测试(c(1)
)失败了。我不确定这是一个错误,还是由于某种原因这是预期的行为。
JSON 查询仍然不起作用。
更新:
这是结果sessionInfo()
:
R version 3.0.3 (2014-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mixtools_1.0.1 segmented_0.3-1.0 MASS_7.3-32 boot_1.3-11 plyr_1.8.1 reshape2_1.4 data.table_1.9.4
[8] stringr_0.6.2 ggplot2_0.9.3.1 XML_3.98-1.1 rmongodb_1.6.5
loaded via a namespace (and not attached):
[1] chron_2.3-45 colorspace_1.2-4 digest_0.6.4 grid_3.0.3 gtable_0.1.2 jsonlite_0.9.7 munsell_0.4.2
[8] proto_0.3-10 Rcpp_0.11.1 scales_0.2.4 tools_3.0.3