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;

posted @ 2014-09-19 10:36  LAOS  阅读(362)  评论(0编辑  收藏  举报