Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created June 1, 2021 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hi-manshu/06ba061d93c668c7b8b85684dc6ac317 to your computer and use it in GitHub Desktop.
Save hi-manshu/06ba061d93c668c7b8b85684dc6ac317 to your computer and use it in GitHub Desktop.
postCollection.aggregate<Post>(
lookup(
"user",
listOf(Post::likes.variableDefinition()),
User::userId
),
match(
expr(
MongoOperator.and from listOf(
MongoOperator.`in` from listOf(User::userId, Post::likes),
MongoOperator.eq from listOf(
User::userId, "_id"
)
)
)
),
Post::likes.unwind(),
group(
fields(
User::userId from Post::likes
)
),
replaceRoot("_id".projection)
).toList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment