func TestUpdate(t *testing.T) { if err := omgo.RunMgFun(mg_instance, mg_collection, func(c *mgo.Collection) error { return c.Update(bson.M{"name": "yoer"}, bson.M{"name": "yoer", "date": time.Now().UnixNano()}) }); nil != err { t.Error(err.Error()) } }
func TestFind(t *testing.T) { find := &DongoData{} if err := omgo.RunMgFun(mg_instance, mg_collection, func(c *mgo.Collection) error { return c.Find(bson.M{"name": "yoer"}).One(find) }); nil != err { t.Error(err.Error()) } t.Log(find) }
func TestInsert(t *testing.T) { if err := omgo.RunMgFun(mg_instance, mg_collection, func(c *mgo.Collection) error { return c.Insert(&DongoData{ Id: bson.NewObjectId(), Name: "yoer", Date: bson.MongoTimestamp(time.Now().UnixNano()), }) }); nil != err { t.Error(err.Error()) } }
func TestCount(t *testing.T) { count := 0 if err := omgo.RunMgFun(mg_instance, mg_collection, func(c *mgo.Collection) error { rs, err := c.Find(bson.M{"name": "yoer"}).Count() count = rs return err }); nil != err { t.Error(err.Error()) } t.Log(count) }