Exemple #1
0
func RemoveFollow(uid string, beuid string) (err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FOLLOW)

	return c.Remove(bson.M{"uid": uid, "beuid": beuid})
}
Exemple #2
0
func InsertFeedLoc(loc model.FeedLoc) (ret model.FeedLoc, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_LOC)

	return loc, c.Insert(loc)
}
Exemple #3
0
func UserLogin(uid string) (err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)
	err = c.Update(bson.M{"uid": uid}, bson.M{"$set": bson.M{"lltime": util.UnixMillSeconds()}, "$inc": bson.M{"logincnt": 1}})
	return
}
Exemple #4
0
func RemoveFeed(id bson.ObjectId) (err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED)

	return c.RemoveId(id)
}
Exemple #5
0
func RemoveFeedLoc(id string) (err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_LOC)

	return c.Remove(bson.M{"fid": id})
}
Exemple #6
0
func InsertFollow(follow model.Follow) (ret model.Follow, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FOLLOW)

	follow.Ctime = util.UnixMillSeconds()
	return follow, c.Insert(follow)
}
Exemple #7
0
func UpdateUserExpand(ue model.UserExpand) (ret model.UserExpand, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)

	cmd := bson.D{{"findAndModify", util.MONGO_COLLECTION_USER_EXPAND}, {"new", true}, {"query", bson.M{"uid": ue.Uid}}, {"update", bson.M{"$set": ue.UserExpandToBson()}}}
	err = c.Database.Run(cmd, &ret)
	return
}
Exemple #8
0
func InsertComment(comment model.Comment) (ret model.Comment, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_COMMENT)

	comment.Cid = bson.NewObjectId()
	comment.Ctime = util.UnixMillSeconds()

	return comment, c.Insert(comment)
}
Exemple #9
0
func InsertUser(user model.User) (ret model.User, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER)

	user.Uid = bson.NewObjectId()
	user.Ctime = util.UnixMillSeconds()

	return user, c.Insert(user)
}
Exemple #10
0
func InsertFeed(feed model.Feed) (ret model.Feed, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED)

	feed.Fid = bson.NewObjectId()
	feed.Ctime = util.UnixMillSeconds()

	return feed, c.Insert(feed)
}
Exemple #11
0
func QueryFollow(uid string, beuid string) (ret model.Follow, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FOLLOW)

	q := c.Find(bson.M{"uid": uid, "beuid": beuid})
	if q.Iter().Next(&ret) {
		return ret, nil
	}
	return ret, mgo.ErrNotFound
}
Exemple #12
0
func QueryFeedLoc(id string) (ret model.FeedLoc, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_LOC)

	q := c.Find(bson.M{"fid": id})
	if q.Iter().Next(&ret) {
		return ret, nil
	}
	return ret, mgo.ErrNotFound
}
Exemple #13
0
func QueryUserExpand(id string) (ret model.UserExpand, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)

	q := c.Find(bson.M{"uid": id})
	if q.Iter().Next(&ret) {
		return ret, nil
	}
	return ret, mgo.ErrNotFound
}
Exemple #14
0
func InsertCommentsDel(comments []model.Comment) (err error) {
	ins := make([]interface{}, len(comments), len(comments))
	for pos, v := range comments {
		ins[pos] = v
	}

	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_COMMENT_DEL)
	return c.Insert(ins...)
}
Exemple #15
0
func InsertUserLocsDel(locs []model.UserLoc) (err error) {
	ins := make([]interface{}, len(locs), len(locs))
	for pos, v := range locs {
		ins[pos] = v
	}

	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_LOC_DEL)
	return c.Insert(ins...)
}
Exemple #16
0
func InsertUserExpandsDel(ues []model.UserExpand) (err error) {
	ins := make([]interface{}, len(ues), len(ues))
	for pos, v := range ues {
		ins[pos] = v
	}

	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND_DEL)
	return c.Insert(ins...)
}
Exemple #17
0
func QueryFeed(id bson.ObjectId) (ret model.Feed, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED)

	q := c.FindId(id)
	if q.Iter().Next(&ret) {
		return ret, nil
	}
	return ret, mgo.ErrNotFound
}
Exemple #18
0
func InsertFeedsDel(feeds []model.Feed) (err error) {
	ins := make([]interface{}, len(feeds), len(feeds))
	for pos, v := range feeds {
		ins[pos] = v
	}

	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_DEL)
	return c.Insert(ins...)
}
Exemple #19
0
func QueryBatchUserExpand(ids []string) (rets []model.UserExpand, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)

	iter := c.Find(bson.M{"uid": bson.M{"$in": ids}}).Iter()
	rets = make([]model.UserExpand, 0, len(ids))
	item := model.UserExpand{}
	for iter.Next(&item) {
		rets = append(rets, item)
	}
	return rets, nil
}
Exemple #20
0
func queryComments(idName string, id string) (rets []model.Comment) {
	rets = make([]model.Comment, 0, 20)
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_COMMENT)

	iter := c.Find(bson.M{idName: id}).Iter()
	item := model.Comment{}
	for iter.Next(&item) {
		rets = append(rets, item)
	}
	return
}
Exemple #21
0
func WithinBoxFeedLoc(loc1 model.LatLon, loc2 model.LatLon) (rets []model.FeedLoc) {
	rets = make([]model.FeedLoc, 0, 20)
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_LOC)

	iter := c.Find(bson.M{"loc.loc": bson.M{"$within": bson.M{"$box": []model.LatLon{loc1, loc2}}}}).Iter()
	item := model.FeedLoc{}
	for iter.Next(&item) {
		rets = append(rets, item)
	}
	return
}
Exemple #22
0
func QueryBatchFeed(ids []bson.ObjectId) (rets []model.Feed, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED)

	iter := c.Find(bson.M{"_id": bson.M{"$in": ids}}).Iter()
	rets = make([]model.Feed, 0, len(ids))
	item := model.Feed{}
	for iter.Next(&item) {
		rets = append(rets, item)
	}
	return rets, nil
}
Exemple #23
0
func WithinCircleFeedLoc(center model.LatLon, radius float64) (rets []model.FeedLoc) {
	rets = make([]model.FeedLoc, 0, 20)
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_FEED_LOC)

	iter := c.Find(bson.M{"loc.loc": bson.M{"$within": bson.M{"$center": []interface{}{center, radius}}}}).Iter()
	item := model.FeedLoc{}
	for iter.Next(&item) {
		rets = append(rets, item)
	}
	return
}
Exemple #24
0
func InsertUserExpand(ue model.UserExpand) (ret model.UserExpand, err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)
	return ue, c.Insert(ue)
}
Exemple #25
0
func RemoveUserExpand(id string) (err error) {
	s := mongo.GetSession()
	defer s.Close()
	c := collection(s, util.MONGO_COLLECTION_USER_EXPAND)
	return c.Remove(bson.M{"uid": id})
}