Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rmongo查询函数给定错误_R_Mongodb_Rmongo - Fatal编程技术网

Rmongo查询函数给定错误

Rmongo查询函数给定错误,r,mongodb,rmongo,R,Mongodb,Rmongo,我正在尝试使用Rmongo库连接R中的mongodb。但查询函数给了我错误 > chn = mongoDbConnect("marketing_db", host = 'localhost', port = 27017) > print(dbShowCollections(chn)) character(0) > results = dbGetQuery(chn, marketing_data, {}, 0, 5) Error in dbGetQuery(chn, market

我正在尝试使用Rmongo库连接R中的mongodb。但查询函数给了我错误

> chn = mongoDbConnect("marketing_db", host = 'localhost', port = 27017)
> print(dbShowCollections(chn))
character(0)
> results = dbGetQuery(chn, marketing_data, {}, 0, 5)
Error in dbGetQuery(chn, marketing_data, { : 
  object 'marketing_data' not found
> results = dbGetQuery(chn, "marketing_data", {}, 0, 5)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘dbGetQuery’ for signature ‘"RMongo", "character", "NULL", "numeric", "numeric"’
> results = dbGetQuery(chn, "marketing_data", query = {}, skip = 0, limit = 5)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘dbGetQuery’ for signature ‘"RMongo", "character", "NULL", "numeric", "numeric"’
其中,marketing_db是db,marketing_数据收集在my mongodb中

以下是mongo控制台的输出:

> show dbs
admin         0.000GB
config        0.000GB
local         0.000GB
marketing_db  0.001GB
myblogs       0.000GB
test          0.003GB
> use marketing_db
switched to db marketing_db
> show collections
marketing_data
> db.marketing_data.count()
7414
> db.marketing_data.find().pretty().limit(1)
{
        "_id" : ObjectId("5b1d65c6cc6e576297462cdc"),
        "custAge" : 55,
        "profession" : "admin.",
        "marital" : "single"
}
我正在为windows 3.4.3和MongoDB 3.6.5使用R


请帮助解决此错误。

尝试将查询json作为字符串传递:

results = dbGetQuery(chn, "marketing_data", "{}", 0, 5)

在第一次尝试中,您没有在代码中设置
marketing\u data
变量。签名也不同:
dbGetQuery(rmongo.object,collection,query,skip=0,limit=1000)
。查询应该是一个字符串,例如,
{}
谢谢Bulat,它工作了,但我还有另一个问题,为什么在dbshowCollections(chn)函数中输出为字符(0)。为什么不显示集合名称?