2

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.

sashkello
  • 17,306
  • 24
  • 81
  • 109
Areza
  • 5,623
  • 7
  • 48
  • 79

1 Answers1

3

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'}")
Stennie
  • 63,885
  • 14
  • 149
  • 175
  • How do I query for an id field where I would need to search by 'key': ObjectId('....'). It is failing for me. – Kumar Deepak Sep 14 '15 at 06:33
  • @KumarDeepak Can you post a separate question with example of the code you've tried and the error(s) you're getting? Would also be helpful to include the version of RMongo you're using. – Stennie Sep 14 '15 at 06:53
  • @KumarDeepak Actually, I see there's a question that needs a relevant answer (which you've also commented on): [Querying RMongo with ObjectId](http://stackoverflow.com/questions/20406329/querying-rmongo-with-objectid). I'll post an answer there ;-) – Stennie Sep 14 '15 at 06:57
  • @KumarDeepak See my answer on http://stackoverflow.com/questions/20406329/querying-rmongo-with-objectid for an example. – Stennie Sep 14 '15 at 07:06
  • Thanks a lot, I had spent hours on this. – Kumar Deepak Sep 14 '15 at 07:10