rmongo and query-ing

2k Views Asked by At

I have difficulty with writing query via rmongo ..

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

now :

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

I appreciate if someone give me some hint and help me to make a table or R list from my database.

1

There are 1 best solutions below

5
On

The query argument for dbGetQuery() should be the data you want to search for, not find_one().

The result of a dbGetQuery() will be a Data Frame.

Example usage:

# 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'}")