rmongo和查询

时间:2012-09-13 08:22:47

标签: r mongodb rmongo

我很难通过rmongo编写查询..

mongo <- mongoDbConnect(dbName="baba", host="inja.com",port='27017')
dbAuthenticate(mongo, 'alaki', 'dolaki')
dbShowCollections(mongo)
> Acol Bcol Ccol Dcol

现在:

result = dbGetQuery(mongo, "settings", "{find_one()}",0,10)
> Error in .jcall(rmongo.object@javaMongo, "S", "dbGetQuery", collection,  : 
      com.mongodb.util.JSONParseException: 
    {find_one()}

如果有人给我一些提示并帮助我从我的数据库中创建一个表或R列表,我感激不尽。

1 个答案:

答案 0 :(得分:3)

dbGetQuery()的查询参数应该是您要搜索的数据,而不是find_one()。

dbGetQuery()的结果将是Data Frame

使用示例:

# Find documents in "settings" collection (no query criteria); limit results to 10
result=dbGetQuery(mongo, "settings","{}",0,10)

# Find all documents that have a value of "blackbox" for the "widget" column
result=dbGetQuery(mongo, "settings","{'widget':'blackbox'}")