How to connect and performe aggregation queries using mongoDb and kotlin?

Hello everyone!

I have managed to connect a kotlin project made in jetpack compose to mongodatabase and can performe CRUD operations.

I am trying to learn how to performe a simple aggregation query such as matching the users age with 20. Lets say that there are 100 people in the document and 35 people with the age of 20. I want the following message “You matched with: 35 people” to be displayed when I press a buttom and this number will adapt dependent on what age the user chooses. Meaning age of 40 will match with 20 users etc that are age 40 within a set of 100 people.

How can this be done using mongoDb and kotlin language in jetpack compose? Appreciate any feedback or advice!

Hi Josef! If you’re building an Android application with JetPack Compose, I’d recommend using the Atlas Device SDK for Kotlin. You can find documentation on how to do a find() here.

If your application is server-side, we have some documentation and code examples around aggregation here using the MongoDB Kotlin Driver for server-side.

Thanks for the feedback! Will try to follow the examples there and see if I can create something similar. If not, I will be back with more questions :slight_smile: @Ashni_Mehta