结合 AND、OR 和字符串匹配的 rmongodb 查询
rmongodb query combining AND, OR, and string match
抱歉,如果此问题已得到解决。
在 mongodb 中,我有一个名为 "main." 的数据库集合,我可以成功 运行 来自 mongodb shell 的以下查询:
db.main.find( {
$or : [
{ $and : [ { "Var1Path": /.*20072.*/ }, { "Var2Path": /.*30033.*/ } ] },
{ $and : [ { "Var1Path": /.*30033.*/ }, { "Var2Path": /.*20072.*/ } ] },
]
} )
我寻求 运行 R 中与 rmongodb 相同的查询。该查询结合了 AND 和 OR。斜杠充当字符串匹配(例如,在名为 Var1Path 的字段中的任意位置找到字符串“20072”)。这可以是 R 中带有 rmondodb 的 运行 吗?如果可以,应该怎么写?
您是否尝试编写一些代码/阅读 rmongodb 小插图?
你需要这样的东西:
and_1 = list("$and" = list( list("Var1Path" = list("$regex" = "20072" )),
list("Var2Path" = list("$regex" = "30033" )) ))
and_2 = list("$and" = list( list("Var1Path" = list("$regex" = "30033" )),
list("Var2Path" = list("$regex" = "20072" )) ))
mongo.find(mongo = mongo, ns = 'db_name.collection_name',
query = list("$or" = list(and_1, and_2)))
所有 rmongodb 用户都应该记住一件事:mognodb 对象和 R 对象之间有非常直接的映射 - 未命名的 list
s 被解析为数组并命名为 list
s 解析为对象。
抱歉,如果此问题已得到解决。
在 mongodb 中,我有一个名为 "main." 的数据库集合,我可以成功 运行 来自 mongodb shell 的以下查询:
db.main.find( {
$or : [
{ $and : [ { "Var1Path": /.*20072.*/ }, { "Var2Path": /.*30033.*/ } ] },
{ $and : [ { "Var1Path": /.*30033.*/ }, { "Var2Path": /.*20072.*/ } ] },
]
} )
我寻求 运行 R 中与 rmongodb 相同的查询。该查询结合了 AND 和 OR。斜杠充当字符串匹配(例如,在名为 Var1Path 的字段中的任意位置找到字符串“20072”)。这可以是 R 中带有 rmondodb 的 运行 吗?如果可以,应该怎么写?
您是否尝试编写一些代码/阅读 rmongodb 小插图?
你需要这样的东西:
and_1 = list("$and" = list( list("Var1Path" = list("$regex" = "20072" )),
list("Var2Path" = list("$regex" = "30033" )) ))
and_2 = list("$and" = list( list("Var1Path" = list("$regex" = "30033" )),
list("Var2Path" = list("$regex" = "20072" )) ))
mongo.find(mongo = mongo, ns = 'db_name.collection_name',
query = list("$or" = list(and_1, and_2)))
所有 rmongodb 用户都应该记住一件事:mognodb 对象和 R 对象之间有非常直接的映射 - 未命名的 list
s 被解析为数组并命名为 list
s 解析为对象。