【问题标题】:Querying a MongoDB database using a list of values使用值列表查询 MongoDB 数据库
【发布时间】:2018-12-20 04:32:01
【问题描述】:

我有一个板球比赛数据库,其中每场比赛都分配了一个唯一的 MatchId。我有一个列表,其中包含我需要从名为“id_list”的 MongoDB 数据库中查询的一些选择匹配项的 Matchids

我在 python 上的 pymongo 中使用的查询是 查询 = { 'MatchId': {'$in': id_list} } 我尝试在 Rmongo 上使用相同的查询

library(RMongo)
mongo <- mongoDbConnect("db_name", "127.0.0.1", 27017)
df_t20 <- dbGetQuery(mongo, 'match_info', '{"MatchType": "T20"}')
id_list<-as.vector(df_t20$MatchId)
t20 <- dbGetQuery(mongo, 'deliveries', '{"MatchId": { $in: id_list} }')
head(t20)

.jcall(rmongo.object@javaMongo, "S", "dbGetQuery", 集合,:com.mongodb.util.JSONParseException:{“MatchId”:{ $in: id_list} } ^

【问题讨论】:

  • 你的 id_list 是数组还是对象?

标签: r mongodb rmongo


【解决方案1】:
library(RMongo)
mongo <- mongoDbConnect("db_name", "127.0.0.1", 27017)
df_t20 <- dbGetQuery(mongo, 'match_info', '{"MatchType": "T20"}')
id_list<-as.vector(df_t20$MatchId)
t20 <- dbGetQuery(mongo, 'deliveries', '{"MatchId": { "$in": id_list} }')
head(t20)

或 试试这个方法

使用 rJson 将 {"MatchId": { "$in": id_list} } 查询转换为 json 对象,然后转换为字符串,

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 2021-05-20
    • 2016-04-07
    • 2020-04-30
    相关资源
    最近更新 更多