Mongodb 执行eval命令

procedure TForm1.BitBtn7Click(Sender: TObject);

var

   query,b1,b2:tbson;

   buf:tbsonbuffer;  

   code:tbsoncodewscope;

begin

  if dbman=nil then dbman:=tdbmanage.create;  

   code:=tbsoncodewscope.Create('function(){var a=db.testc.find();return a[0].name;}',bson([]));

   buf:=tbsonbuffer.Create;  buf.append('eval',code);

 

 query:=buf.finish;

  showmessage(query.Displaystr.ToString);

 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;

//修改数据库字段名

function()
{
  var a=db.testc.findOne({"name":"fangjun"});
 a.content.departs[0].depname="glx";
db.testc.save(a);
 return a;
 
}

posted @ 2014-09-19 14:15  LAOS  阅读(2578)  评论(0编辑  收藏  举报