Beispiel #1
0
func (u *user) Upsert(user *model.User) (*model.User, error) {
	changed, err := u.C().Upsert(Query{"id": user.ID}, user)
	if err != nil {
		return nil, err
	}

	if changed.UpsertedId == nil {
		return u.First(Query{"id": user.ID}), nil
	} else {
		user.ObjectId = changed.UpsertedId.(bson.ObjectId)
		return user, nil
	}
}
Beispiel #2
0
func (u *user) Insert(user *model.User) error {
	user.ObjectId = bson.NewObjectId()
	return u.C().Insert(user)
}