gomongo是Go语言访问MongoDB数据库的开发包。
示例代码:
packagemainimport"github.com/mikejs/gomongo/mongo"funcmain(){conn,_:=mongo.Connect("127.0.0.1")collection:=conn.GetDB("test").GetCollection("test_collection")doc,_:=mongo.Marshal(map[string]string{"_id":"doc1","title":"AMongodocument","content":"Testing,1.2.3.",})collection.Insert(doc)query,_:=mongo.Marshal(map[string]string{"_id":"doc1"})got,_:=collection.FindOne(query)mongo.Equal(doc,got)//true!collection.Drop()}
评论