Open komalsrathi opened 7 years ago
Can you make another connection:
testConn <- mongoDbConnect(dbName = 'test', host = 'localhost', port = '27018')
auth <- dbAuthenticate(rmongo.object = testConn, username = 'user', password = 'pass')
``
Hi all,
Is it possible in RMongo to query against a non-admin authentication database? I had this issue with mongolite as well, and tried using RMongo as a solution, and believe I am having the same issue. I have a database, collection, and documents already created (I don't want to insert anything myself)—is there a way for me to query that collection (which I did not create myself), without being an admin?
Thank you, Jenna
Can you list the commands you tried?
I think it should work.
I tried:
dbGetQuery(my_coll, collec, '{}')
, where my_coll is the mongo connection using mongolite and collec is the collection name. The goal of this was to do sort of anls
using RMongo. The error was:Error in (function (classes, fdef, table) : unable to find an inherited method for function 'dbGetQuery' for signature '"mongo", "character", character"
I assumed this had something to do with the fact that I was using a connection made in mongolite rather than in RMongo, so I tried making a connection in RMongo, and did this:
mon <- mongoDbConnect("DBname", "host name", port)
dbShowCollections(mon)
and the error was:Error in .jcall(RMongo.object@javaMongo, "[S", "dbShowCollections") : com.mongodb.CommandFailureException: {"serverUsed": , "ok" : 0.0 , "errmsg" : "not authorized on collection to execute command {listCollections: \"collectionName\"}", "code" : 13, "codeName" : "Unauthorized"}
Resolved, thank you for your help!
Can you leave your solution so it can help others?
Not sure how to resolve in RMongo, but in mongolite, the mongo() must have a database and a collection as parameters, whereas the URL that mongo() takes in uses the authentication database. All different things, and all need to be included. RMongo connects to databases slightly differently, so I don't know how to work around that. Sorry this was unhelpful for RMongo.
Hi,
I am using RMongo to connect to MongoDB.
However, I want to switch to another database called
test
and query it. How can I do that?Thanks, Komal