Beispiel #1
0
func UpdateAccountByMgoId(id interface{}, ismgoid bool, update interface{}) (bool, error) {
	id, err := tool.GetTrueQueryId(id, ismgoid)
	if err != nil {
		return false, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	session, _, collection, err := tool.GetCollection(nil, DBNAME, COLLECTIONNAME)
	if err != nil {
		return false, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	defer session.Close()
	err = collection.UpdateId(id, update)
	if err != nil {
		return false, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	return true, nil
}
Beispiel #2
0
func GetAccountByMgoId(id interface{}, ismgoid bool) (*model.Account, error) {
	id, err := tool.GetTrueQueryId(id, ismgoid)
	if err != nil {
		return nil, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	session, _, collection, err := tool.GetCollection(nil, DBNAME, COLLECTIONNAME)
	if err != nil {
		return nil, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	account := new(model.Account)
	defer session.Close()
	err = collection.FindId(id).One(account)
	if err != nil {
		return nil, errors.ErrorCodeMongoError.WithArgs(err.Error())
	}
	return account, nil
}