#1 2014-12-18 22:23:47

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

[mongodb] FindDocs with bad syntax

Hi AB,

I ran into this error:

procedure TForm1.Button1Click(Sender: TObject);
var
 t:integer;
 Coll: TMongoCollection;
 Docs: TVariantDynArray;
begin
 log('Start');
 try
  fClient:=TMongoClient.Create('localhost',27017);

  fDB:=fClient.Database['test25'];
  Coll := fDB.CollectionOrCreate['testColl'];

  coll.Insert('{"Age":?,Name: ?}',[1,'test1']);
  coll.Insert('{"Age":?,Name: ?}',[2,'test2']);

  if BADjson.Checked then
  begin
   try
    coll.FindDocs('{Age:{$gt,1}}',[],docs,null); // <------------------------ bad syntax
    for t:=Low(docs) to High(docs) do if not varisnull(docs[t].Name) then Log('Docs:'+docs[t].Name);
   except
    on e: exception do  log('EXC1: '+e.Message);
   end;
  end;

  Coll := fDB.CollectionOrCreate['testColl'];

  try
   coll.FindDocs('{Age:{$gt:1}}',[],docs,null); // <------------------------ right syntax
   for t:=Low(docs) to High(docs) do if not varisnull(docs[t].Name) then Log('Docs:'+docs[t].Name);
  except
   on e: exception do  log('EXC2: '+e.Message);
  end;


 finally
  FreeAndNil(fClient);
  log('end');
 end;
end;

with BADsyntax checked output is:
EXC1: Server reset the connection: probably due to a bad formatted BSON request
EXC2: Server reset the connection: probably due to a bad formatted BSON request



...but the second call is correct.
How to reset the error (without having to reconnect) ?

Offline

#2 2014-12-18 23:35:07

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

Re: [mongodb] FindDocs with bad syntax

Of course, the syntax is {$age:{$gt:1}}

The documentation was misleading.
Should be fixed now.
See http://synopse.info/fossil/info/f839bfad2a

Offline

#3 2014-12-19 00:47:22

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

Re: [mongodb] FindDocs with bad syntax

How to reset the error (without having to reconnect) ?

Offline

#4 2014-12-19 08:51:15

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

Re: [mongodb] FindDocs with bad syntax

If the transmitted BSON is incorrect, this is the server which disconnects.

So the client needs to reconnect.

Offline

Board footer

Powered by FluxBB