首页 > 代码库 > delphi mongodb 调用group

delphi mongodb 调用group

var   query,b1,b2:tbson;   buf:tbsonbuffer;   code:TBsonCodeWScope; begin if dbman=nil then dbman:=tdbmanage.create;

  buf:=tbsonbuffer.Create;   buf.startObject(‘group‘);   buf.append(‘ns‘,‘testc‘);

  buf.startObject(‘key‘);   buf.append(‘name‘,null);   buf.finishObject;

  buf.startObject(‘initial‘);   buf.append(‘num‘,0);   buf.finishObject;

   code:=tbsoncodewscope.Create(‘function(doc,prev){ prev.num++;}‘,bson([]));    buf.append(‘$reduce‘,code);

  buf.finishObject;   query:=buf.finish;

  b2:=dbman.mongodbs.mongo.command(‘prjdbs‘,query);

  b1:=dbman.mongodbs.mongo.getLastErr(‘prjdbs‘);   if b1<>nil then showmessage(b1.Displaystr.ToString);   showmessage(b2.Displaystr.ToString);

end;

delphi mongodb 调用group