コード例 #1
0
ファイル: ArticleRepository.go プロジェクト: arahansa/blogo
func Save(article *domain.Article) (int, error) {
	change := mgo.Change{
		Update:    bson.M{"$inc": bson.M{"seq": 1}},
		ReturnNew: true,
	}
	counter := Counter{}
	colCounter.Find(bson.M{"_id": "article"}).Apply(change, &counter)
	article.Id = counter.Seq
	article.DayWrite = time.Now()
	colArticle.Insert(article)
	return article.Id, nil
}