stijnsanders / TMongoWire

Delphi MongoDB driver
MIT License
102 stars 37 forks source link

How to authenticate to a collection on Mongolab? #13

Closed sitcon40670 closed 11 years ago

sitcon40670 commented 11 years ago

Trying to connect to MongoLab works fine.

Following authentification fails: (accounts is a collection within a database).

MongoWireAuthenticate(mdb,'accounts',usernameonMongoLab,pwd);

also tried a user from the database --> fails as well.

Mongoshell can connect fine with % mongo acct.mongolab.com:33037/database -u -p

Any idea on how to set this up in TMongoWire?

stijnsanders commented 11 years ago

The Collection name may have to be a multi-part name, try MongoWireAuthenticate(mdb,'db.accounts', or 'system.accounts', if that doesn't work I should take some time to investigate what the mongo shell does

sitcon40670 commented 11 years ago

Hello,

unfortunately using dbname.collectionname throws a malformed command exception.

any ideas?

stijnsanders commented 11 years ago

I'll see when I can put up a server with authentication and find out what the client is doing different than TMongoWire

sitcon40670 commented 11 years ago

Hello,

any news on that issue?

stijnsanders commented 11 years ago

Haven't taken the time yet to set up a local mongodb install with authentication, though I just now see mongolab.com has a free offering. I'll try to fit in some time to take a look at it soon.

stijnsanders commented 11 years ago

I've tried this, and it works (replaced my personal data by 'MyMongoLab...' below) I've created mongolab account, and a mongolab db 'test1' (somewhere in the Amazon Ireland datacenter) By using 'test1.db1' (note: just 'test1' in the MongoWireAuthenticate call) I see the 'db1' collection in the mongolab admin website.

procedure TForm1.Button9Click(Sender: TObject);
var
  m:TMongoWire;
  d:IBSONDocument;
begin
  m:=TMongoWire.Create;
  try
    m.Open('ds0MyMongoLabNr.mongolab.com',MyMongoLabNr);
    MongoWireAuthenticate(m,'test1','MyMongoLabUserName','MyMongoLabPwd');
    //test insert
    m.Insert('test1.db1',BSON(['test','x']));
    //test get
    d:=m.Get('test1.db1',BSON);
    Button9.Caption:=VarToStr(d['test']);
  finally
    m.Free;
  end;
end;