本文整理汇总了Golang中labix/org/v2/mgo/bson.ObjectId类的典型用法代码示例。如果您正苦于以下问题:Golang ObjectId类的具体用法?Golang ObjectId怎么用?Golang ObjectId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CountFollowingBrandByUserId
func CountFollowingBrandByUserId(userId bson.ObjectId) (num int, err error) {
if !userId.Valid() {
err = global.InvalidIdError
return
}
return CountFollowBrand(bson.M{"userid": userId})
}
示例2: CountReviewByBrandId
func CountReviewByBrandId(brandId bson.ObjectId) (num int, err error) {
if !brandId.Valid() {
err = global.InvalidIdError
return
}
return CountReview(bson.M{"brandid": brandId})
}
示例3: GetRead
func (c Blog) GetRead(id bson.ObjectId) revel.Result {
if id.Hex() != "" {
article := models.GetArticleByObjectId(c.MongoSession, id)
return c.Render(article)
}
return c.NotFound("Invalid article Id.")
}
示例4: CountReviewByProductId
func CountReviewByProductId(productId bson.ObjectId) (num int, err error) {
if !productId.Valid() {
err = global.InvalidIdError
return
}
return CountReview(bson.M{"productid": productId})
}
示例5: FindSomeByUserId
func FindSomeByUserId(userId bson.ObjectId) (r []*Note, err error) {
if !userId.Valid() {
err = global.InvalidIdError
return
}
return FindAll(bson.M{"authorid": userId})
}
示例6: FindById
func FindById(id bson.ObjectId) (review *Review, err error) {
if !id.Valid() {
err = global.InvalidIdError
return
}
return FindOne(bson.M{"_id": id})
}
示例7: FindByUserId
func FindByUserId(userId bson.ObjectId) (r []*FollowBrand, err error) {
if !userId.Valid() {
err = global.InvalidIdError
return
}
return FindAll(bson.M{"userid": userId})
}
示例8: CountBrandFollowerByBrandId
func CountBrandFollowerByBrandId(brandId bson.ObjectId) (num int, err error) {
if !brandId.Valid() {
err = global.InvalidIdError
return
}
return CountFollowBrand(bson.M{"brandid": brandId})
}
示例9: FindByBrandId
func FindByBrandId(brandId bson.ObjectId) (r []*FollowBrand, err error) {
if !brandId.Valid() {
err = global.InvalidIdError
return
}
return FindAll(bson.M{"brandid": brandId})
}
示例10: FindByUserAndBrandId
func FindByUserAndBrandId(userId, brandId bson.ObjectId) (followBrand *FollowBrand, err error) {
if !userId.Valid() || !brandId.Valid() {
err = global.InvalidIdError
return
}
return FindOne(bson.M{"userid": userId, "brandid": brandId})
}
示例11: FindSomeByAuthorId
func FindSomeByAuthorId(authorId bson.ObjectId) (r []*Post, err error) {
if !authorId.Valid() {
err = global.InvalidIdError
return
}
return FindAll(bson.M{"authorid": authorId})
}
示例12: FindById
func FindById(id bson.ObjectId) (product *Product, err error) {
if !id.Valid() {
err = global.InvalidIdError
return
}
return FindOne(bson.M{"_id": id})
}
示例13: CanModifyComment
// Only called when doing update or delete.
// At inserting, user.OkayToDoAction is sufficient.
// This needs additional action: you can only update or delete a given comment only if it's yours (under a certain level).
func CanModifyComment(db *mgo.Database, inp map[string][]string, correction_level int, user_id bson.ObjectId, user_level int) error {
rule := map[string]interface{}{
"content_id": "must",
"comment_id": "must",
"type": "must",
}
dat, err := extract.New(rule).Extract(inp)
if err != nil {
return err
}
// Even if he has the required level, and he is below correction_level, he can't modify other people's comment, only his owns.
// So we query here the comment and check who is the owner of it.
if user_level < correction_level {
content_id_str := basic.StripId(dat["content_id"].(string))
comment_id_str := basic.StripId(dat["comment_id"].(string))
auth, err := findCommentAuthor(db, content_id_str, comment_id_str)
if err != nil {
return err
}
if auth.Hex() != user_id.Hex() {
return fmt.Errorf("You are not the rightous owner of the comment.")
}
}
return nil
}
示例14: UpdateByPk
func (a *AbstractModel) UpdateByPk(id bson.ObjectId, update interface{}) error {
if !id.Valid() {
return errors.New("20314")
}
return a.Update(M{"_id": id}, update, true)
}
示例15: DeleteByUserAndBrandId
func DeleteByUserAndBrandId(userId, brandId bson.ObjectId) (err error) {
if !userId.Valid() || !brandId.Valid() {
err = global.InvalidIdError
return
}
return DeleteFollowBrand(bson.M{"userid": userId, "brandid": brandId})
}