func CountFollowingBrandByUserId(userId bson.ObjectId) (num int, err error) { if !userId.Valid() { err = global.InvalidIdError return } return CountFollowBrand(bson.M{"userid": userId}) }
func FindById(id bson.ObjectId) (product *Product, err error) { if !id.Valid() { err = global.InvalidIdError return } return FindOne(bson.M{"_id": id}) }
func FindById(id bson.ObjectId) (review *Review, err error) { if !id.Valid() { err = global.InvalidIdError return } return FindOne(bson.M{"_id": id}) }
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) }
func FindSomeByUserId(userId bson.ObjectId) (r []*Note, err error) { if !userId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"authorid": userId}) }
func CountBrandFollowerByBrandId(brandId bson.ObjectId) (num int, err error) { if !brandId.Valid() { err = global.InvalidIdError return } return CountFollowBrand(bson.M{"brandid": brandId}) }
func CountReviewByProductId(productId bson.ObjectId) (num int, err error) { if !productId.Valid() { err = global.InvalidIdError return } return CountReview(bson.M{"productid": productId}) }
func CountReviewByBrandId(brandId bson.ObjectId) (num int, err error) { if !brandId.Valid() { err = global.InvalidIdError return } return CountReview(bson.M{"brandid": brandId}) }
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}) }
func FindByUserId(userId bson.ObjectId) (r []*FollowBrand, err error) { if !userId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"userid": userId}) }
func FindByBrandId(brandId bson.ObjectId) (r []*FollowBrand, err error) { if !brandId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"brandid": brandId}) }
func FindSomeByAuthorId(authorId bson.ObjectId) (r []*Post, err error) { if !authorId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"authorid": authorId}) }
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}) }
func FindSomeByBrandId(brandId bson.ObjectId) (rs []*Review, err error) { if !brandId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"brandid": brandId}) }
func FindSomeByProductId(productId bson.ObjectId) (rs []*Review, err error) { if !productId.Valid() { err = global.InvalidIdError return } return FindAll(bson.M{"productid": productId}) }
func (ctx *DBCtx) AllContact(offset bson.ObjectId, limit int) []Contact { conts := []Contact{} if offset.Valid() { ctx.contColl.Find(bson.M{"_id": bson.M{"$gt": offset}}).Limit(limit).All(&conts) } else { ctx.contColl.Find(nil).Limit(limit).All(&conts) } return conts }
func (ctx *DBCtx) EntryByTag(tag string, offset bson.ObjectId, limit int) []Entry { entrys := []Entry{} if offset.Valid() { ctx.entryColl.Find(bson.M{ "_id": bson.M{"$gt": offset}, "tags": tag, }).Limit(limit).All(&entrys) } else { ctx.entryColl.Find(bson.M{"tags": tag}).Limit(limit).All(&entrys) } println(len(entrys)) return entrys }
func (ctx *DBCtx) CatTree(root bson.ObjectId) []Catergory { all := []Catergory{} var query *mgo.Query if root.Valid() { query = ctx.catColl.Find(bson.M{"ancestors": root}) } else { query = ctx.catColl.Find(bson.M{"parent": bson.M{"$exists": false}}) } query.All(&all) return all }
func (self *Collection) DocumentLabel(docId bson.ObjectId, labelSelectors ...string) (string, error) { if !docId.Valid() { return "", fmt.Errorf("Invalid bson.ObjectId") } if len(labelSelectors) == 0 { labelSelectors = self.DocLabelSelectors } if len(labelSelectors) == 0 { // No label selectors, use hex ID as label count, err := self.collection.FindId(docId).Count() if err != nil { return "", err } if count == 0 { return "", fmt.Errorf("No document with ID '%s' in collection '%s'", docId.Hex(), self.Name) } return docId.Hex(), nil } labels := make([]string, len(labelSelectors)) for i, selector := range labelSelectors { if len(selector) == 0 { return "", fmt.Errorf("Label selector must not be an empty string") } selector = strings.ToLower(selector) var doc bson.M err := self.collection.FindId(docId).Select(bson.M{selector: 1}).One(&doc) if err != nil { return "", err } var label interface{} if strings.IndexRune(selector, '.') != -1 { for _, subSel := range strings.Split(selector, ".") { label, _ = doc[subSel] if label == nil { break } doc, _ = label.(bson.M) if doc == nil { break } } } else { label, _ = doc[selector] } if label != nil { // Support the basic BSON types from unmarshalling switch s := label.(type) { case string: labels[i] = s case int: labels[i] = strconv.Itoa(s) case float64: labels[i] = strconv.FormatFloat(s, 'f', -1, 64) case bool: labels[i] = strconv.FormatBool(s) case bson.ObjectId: labels[i] = s.Hex() default: return "", fmt.Errorf("Can't get label of %s for '%s' because it is of type %T", docId.Hex(), selector, label) } } } label := strings.Join(labels, self.DocLabelSeparator) label = strings.TrimSpace(utils.RemoveMultipleWhiteSpace(label)) return label, nil }
func FindById(id bson.ObjectId) (user *User, err error) { if !id.Valid() { return } return FindOne(bson.M{"_id": id}) }
func FindById(id bson.ObjectId) (brand *Brand, err error) { if !id.Valid() { return } return FindOne(bson.M{"_id": id}) }