Пример #1
0
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())
	}
}
Пример #2
0
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)
}
Пример #3
0
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())
	}
}
Пример #4
0
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)
}