Example #1
0
func (datastore *DataStore) UpdatePerson(id string, person model.Person) error {
	if !bson.IsObjectIdHex(id) {
		return errors.New("Invalid Id")
	}

	personId := bson.ObjectIdHex(id)
	personDocument := model.PersonDocument{}
	personDocument.Id = personId
	personDocument.Name = person.Name
	personDocument.Gender = person.Gender
	personDocument.Age = person.Age

	return datastore.session.DB(DBNAME).C(TABLE).UpdateId(personId, personDocument)
}
Example #2
0
func (datastore *DataStore) InsertPerson(person *model.Person) (string, error) {
	personDocument := model.PersonDocument{}
	personDocument.Id = bson.NewObjectId()
	personDocument.Name = person.Name
	personDocument.Gender = person.Gender
	personDocument.Age = person.Age

	err := datastore.session.DB(DBNAME).C(TABLE).Insert(personDocument)
	if err != nil {
		return "", err
	} else {
		return personDocument.Id.String(), nil
	}
}