/** *插入一个对象 */ func (bm BaseModel) InsertObjects(obj interface{}) bool { log.Println(obj) structMap := u.Struct2Map(obj) log.Println(structMap) defer bm.Session.Close() err := bm.Collection.Insert(structMap) if err != nil { log.Println(err) return false } return true }
/** *query一个对象 */ func (bm BaseModel) QueryObjetc() []bson.M { log.Println("----------查询------------") defer bm.Session.Close() var result = []bson.M{} log.Println("bm.Object", bm.Object) structMap := u.Struct2Map(bm.Object) err := bm.Collection.Find(structMap).All(&result) if err != nil { log.Println(err) //return err } return result }