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}) }
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) }
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 }
func RemoveFeed(id bson.ObjectId) (err error) { s := mongo.GetSession() defer s.Close() c := collection(s, util.MONGO_COLLECTION_FEED) return c.RemoveId(id) }
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}) }
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) }
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 }
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) }
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) }
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) }
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 }
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 }
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 }
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...) }
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...) }
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...) }
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 }
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...) }
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 }
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 }
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 }
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 }
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 }
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) }
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}) }