mongo-d-driver是MongoDB的D语言开发包。
示例代码:
/**make:dmd-version=D2-Iexportlibmongod-D2.aexample/connect.d**-Iexport:pathtothefoldercontainingthefiles:*bson.di,bson_h.di,md5.di,mongo.di,mongo_h.di,myversion.di,net.di,numbers.di*/moduleexample;importstd.stdio;privateimportmongod.mongo_h;privateimportmongod.mongo;privateimportmongod.bson_h;privateimportmongod.bson;voidmain(char[][]args){mongoconn;stringcollection="test";stringhost="localhost";intport=27017;char*col=cast(char*)collection;char*ns=cast(char*)(collection~".simple");try{mongo_connect(&conn,host,port);writeln("connecttomongodb[",host,":",port,"]sucessful");mongo_set_op_timeout(&conn,1000);}catch(Exceptionex){writeln("failedtoconnecttomongodb,err=",ex.msg);}}
评论