我正在使用 mongolite 包从 MongoDB 连接和检索数据。 如何在 mongolite 查找查询中传递值
##connecting mongodb
library(mongolite)
mongo<-mongolite::mongo(collection = "Sample", db = "Test", url =
"mongodb://User:123@Wyyuyu:13333/ty2_U",verbose = TRUE)
## getting all data from collection data from collection below query is working fine.
values <- mongo$find()
## But I want to filter specific value by passing value.
for(i in c("process","check","queue"))
{
values <- mongo$find('{"field" : i}',)
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试上面的代码,我会遇到以下问题。请帮我解决
Error: Invalid JSON object: {"field" : i}
Run Code Online (Sandbox Code Playgroud) 我有一个称为df的数据框,我需要使用filter()。pls检查从数据框中过滤数据
我的数据框
Queue project._id project.ProjectName project.Status project.CreatedBy project.Createdtime X.gender
first 111 Travel 1 manchi 2017-04-24 18:50:27 male
last 111 2334 1 mono 2017-04-24 18:50:27 Female
first 111 556 1 gunal 2017-04-24 18:50:27 male
first 7888 classical 1 manchi 2017-04-24 18:50:27 Female
Run Code Online (Sandbox Code Playgroud)
我尝试使用dplyr通过以下代码过滤数据。
Finalfilter<-df%>%
filter(project.ProjectName == "Travel",Queue=="first")%>%
select(X.gender.)
Run Code Online (Sandbox Code Playgroud)
我的预期结果是
Queue project._id project.ProjectName project.Status project.CreatedBy project.Createdtime X.gender
first 111 Travel 1 manchi 2017-04-24 18:50:27 male
first 111 556 1 gunal 2017-04-24 18:50:27 male
Run Code Online (Sandbox Code Playgroud)
但是我低于错误,请帮助我解决此问题。
错误:列
project
必须是一维原子向量或列表
dput。
structure(list(Queue = c("first", "last", …
Run Code Online (Sandbox Code Playgroud)