I’m struggling to process a query via mongo remote access using Kotlin.
Referencing this section, which seems to be outdated?
The snippet offered looks like this:
val queryFilter = Document("_partition", "Store 42")
val findTask = mongoCollection.find(queryFilter).iterator()
findTask.getAsync { task ->
if (task.isSuccess) {
val results = task.get()
Log.v("EXAMPLE", "successfully found all plants for Store 42:")
while (results.hasNext()) {
Log.v("EXAMPLE", results.next().toString())
}
} else {
Log.e("EXAMPLE", "failed to find documents with: ${task.error}")
}
}
But when I try to call .getAsync on the iterator, I run into trouble. There is no .getAsync. There’s a getResult. But I can’t even figure out how to get that to do anything.
My code at the moment (just trying to test by pulling a doc with a specific _id) looks like this:
val client = realmApp.currentUser()?.getMongoClient("mongodb-atlas")
val database = client?.getDatabase("funky_radish_db")
val collection = database?.getCollection("Recipe")
val queryFilter = Document("_id", "617ee621638d87c7faf71c9f")
val findTask = collection?.find(queryFilter)?.iterator()
Log.d("API", "task: $findTask")
And the output is
task: com.google.android.gms.tasks.zzu@475b07a
How do I work with these task objects? Was .getAsync deprecated?
And, if I can get that part working, how do I adjust the query filter to work for an _id_in query?
something like what I was able to accomplish in Swift using this:
let queryFilter: Document = ["_id": ["$in": recipes]]