#1 2016-05-13 09:38:57

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

MongoDb Version >=3.0

Hello, I realized that with version 3.0 you can not receive the collection list using this method:

constructor TMongoDatabase

[..]

  if colls.Init(Client.Connections[0].GetBSONAndFree(
     TMongoRequestQuery.Create(aDatabaseName+'.system.namespaces',null,'name',maxInt))) then
    // e.g. [ {name:"test.system.indexes"}, {name:"test.test"} ]
    while colls.Next do begin
      full := colls.item.DocItemToRawUTF8('name');
      if full<>'' then begin
        split(full,'.',db,coll);
        if db<>aDatabaseName then
          raise EMongoConnectionException.CreateUTF8(
            '%.Create: invalid "%" collection name for DB "%"',
            [self,full,aDatabaseName],Client.Connections[0]);
        fCollections.AddObject(coll,TMongoCollection.Create(self,coll));
      end;
    end;

I made a change to use the new method (listCollections):

   Client.Connections[0].RunCommand(aDatabaseName,'listCollections',Vresponse);

   if not varisnull(Vresponse) then
   begin
    for t:=0 to Vresponse.cursor.firstBatch._count-1 do
    begin
     v:=Vresponse.cursor.firstBatch._(t);
     coll:=V.name;
     if coll<>'' then
      fCollections.AddObject(coll,TMongoCollection.Create(self,coll));
    end;
   end;

Offline

#2 2016-05-13 11:12:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: MongoDb Version >=3.0

Please check http://synopse.info/fossil/info/512a3e3265

Thanks for the feedback!

Offline

Board footer

Powered by FluxBB