aggregations

package
v0.0.0-...-367ce81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BanRelationActor = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameUsers,
			LocalField:   "actor_id",
			ForeignField: "_id",
			As:           "actors",
		},
	}},
	{{
		Key: "$set",
		Value: bson.M{
			"actor": bson.M{"$first": "$actors"},
		},
	}},
}

Ban Relations

Input: Ban Adds Field: "actor" as User Output: Ban

View Source
var BanRelationVictim = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameUsers,
			LocalField:   "victim_id",
			ForeignField: "_id",
			As:           "victims",
		},
	}},
	{{
		Key: "$set",
		Value: bson.M{
			"victim": bson.M{"$first": "$victims"},
		},
	}},
}

Ban Relations

Input: Ban Adds Field: "victim" as User Output: Ban

View Source
var EmoteSetRelationActiveEmotes = mongo.Pipeline{

	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameEmotes,
			LocalField:   "emotes.id",
			ForeignField: "versions.id",
			As:           "_emotes",
		},
	}},

	{{
		Key: "$set",
		Value: bson.M{
			"emotes": bson.M{
				"$map": bson.M{
					"input": "$emotes",
					"in": bson.M{
						"$mergeObjects": bson.A{
							"$$this",
							bson.M{
								"emote": bson.M{
									"$arrayElemAt": bson.A{
										"$_emotes",
										bson.M{"$indexOfArray": bson.A{"$_emotes._id", "$$this.id"}},
									},
								},
							},
						},
					},
				},
			},
		},
	}},
}

Emote Set Relations

Input: EmoteSet Adds Field: "emotes" as []ActiveEmote with the "emote" field added to each ActiveEmote object Output: User

View Source
var ReportRelationReporter = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameUsers,
			LocalField:   "reporter_id",
			ForeignField: "_id",
			As:           "reporters",
		},
	}},
	{{
		Key: "$set",
		Value: bson.M{
			"reporter": bson.M{"$first": "$reporters"},
		},
	}},
	{{Key: "$unset", Value: bson.A{"reporters"}}},
}

Report Relations

Input: Report Adds Field: "reporter" as User Output: Report

View Source
var UserRelationBans = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.LookupWithPipeline{
			From: mongo.CollectionNameBans,
			Let:  bson.M{"user_id": "$_id"},
			Pipeline: &mongo.Pipeline{
				{{
					Key: "$match",
					Value: bson.M{
						"$expr": bson.M{
							"$eq": bson.A{"$victim_id", "$$user_id"},
						},
						"$or": bson.A{
							bson.M{"expire_at": time.Time{}},
							bson.M{
								"expire_at": bson.M{"$gt": time.Now()},
							},
						},
					},
				}},
			},
			As: "bans",
		},
	}},
}

User Relations

Input: User Adds Field: "bans" as []Ban Output: User

View Source
var UserRelationConnections = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         "user_connections",
			LocalField:   "connection_ids",
			ForeignField: "_id",
			As:           "connections",
		},
	}},
}
View Source
var UserRelationEditorOf = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.LookupWithPipeline{
			From: mongo.CollectionNameUsers,
			Let:  bson.M{"user_id": "$_id"},
			Pipeline: &mongo.Pipeline{
				{{
					Key: "$match",
					Value: bson.M{
						"$expr": bson.M{"$in": bson.A{"$$user_id", "$editors.id"}},
					},
				}},
				{{
					Key: "$project",
					Value: bson.M{
						"user": "$$ROOT",
						"as_editor": bson.M{
							"$mergeObjects": bson.M{
								"$filter": bson.M{
									"input": "$editors",
									"as":    "u_editor_of",
									"cond":  bson.M{"$eq": bson.A{"$$u_editor_of.id", "$$user_id"}},
								},
							},
						},
					},
				}},
				{{
					Key: "$project",
					Value: bson.M{
						"id":          "$_id",
						"permissions": "$as_editor.permissions",
						"connections": "$as_editor.connections",
						"visible":     "$as_editor.visible",
						"user":        "$user",
					},
				}},
				{{Key: "$unset", Value: bson.A{"_id"}}},
			},
			As: "editor_of",
		},
	}},
}

User Relations

Input: User Add Fields: "editor_of" as []UserEditor with the "user" field added to each UserEditor object Output: User

View Source
var UserRelationEditors = []bson.D{

	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameUsers,
			LocalField:   "editors.id",
			ForeignField: "_id",
			As:           "_ed",
		},
	}},
	{{
		Key: "$set",
		Value: bson.M{
			"editors": bson.M{
				"$map": bson.M{
					"input": "$editors",
					"in": bson.M{
						"$mergeObjects": bson.A{
							"$$this",
							bson.M{
								"user": bson.M{
									"$arrayElemAt": bson.A{
										"$_ed",
										bson.M{"$indexOfArray": bson.A{"$_ed._id", "$$this.id"}},
									},
								},
							},
						},
					},
				},
			},
		},
	}},
}

User Relations

Input: User Adds Field: "editors" as []UserEditor with the "user" field added to each UserEditor object Output: User

View Source
var UserRelationOwnedEmotes = []bson.D{
	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameEmotes,
			LocalField:   "_id",
			ForeignField: "owner_id",
			As:           "owned_emotes",
		},
	}},
}

User Owned Emote Relations

Input: User Adds Field: "owned_emotes" as []Emote Output: User

View Source
var UserRelationRoles = []bson.D{

	{{
		Key: "$lookup",
		Value: mongo.LookupWithPipeline{
			From: mongo.CollectionNameEntitlements,
			Let:  bson.M{"user_id": "$_id"},
			Pipeline: &mongo.Pipeline{
				bson.D{{
					Key: "$match",
					Value: bson.M{
						"disabled": bson.M{"$not": bson.M{"$eq": true}},
						"kind":     "ROLE",
						"$expr": bson.M{
							"$eq": bson.A{"$user_id", "$$user_id"},
						},
					},
				}},
			},
			As: "role_entitlements",
		},
	}},

	{{
		Key: "$set",
		Value: bson.M{
			"role_ids": bson.M{
				"$concatArrays": bson.A{
					bson.M{"$ifNull": bson.A{"$role_ids", bson.A{}}},
					"$role_entitlements.data.ref",
				},
			},
		},
	}},

	{{Key: "$unset", Value: bson.A{"role_entitlements"}}},

	{{
		Key: "$lookup",
		Value: mongo.Lookup{
			From:         mongo.CollectionNameRoles,
			LocalField:   "role_ids",
			ForeignField: "_id",
			As:           "roles",
		},
	}},
}

User Relations

Input: User Adds Field: "roles" as []Role Output: User

Functions

func Combine

func Combine(s ...mongo.Pipeline) mongo.Pipeline

func CombinePtr

func CombinePtr(s ...mongo.Pipeline) *mongo.Pipeline

func GetEmoteRelationshipOwner

func GetEmoteRelationshipOwner(opt UserRelationshipOptions) []bson.D

Emote Relations

Input: Emote Adds Field: "owner" as User Output: Emote

func MergeArrays

func MergeArrays(key, mergeWith, mergePath, mergeKey string) bson.D

MergeArrays combines two arrays and adds a new field from one to the other on corresponding elements

func ReportRelationAssignees

func ReportRelationAssignees() mongo.Pipeline

Report Relations

Input: Report Adds Field: "assignees" as []User Output: Report

func UserConnectionEmoteSetRelation

func UserConnectionEmoteSetRelation() mongo.Pipeline

User Relations Input: User Adds Field: "emote_set" of []connections as EmoteSet

Types

type UserRelationshipOptions

type UserRelationshipOptions struct {
	Editors       bool
	Roles         bool
	ChannelEmotes bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL