kmongo
kmongo copied to clipboard
Support for stitch apps
This might be completely out of left field, but is there any way to use KMongo to connect to MongoDB via stitch API? There is a JavaScript stitch API and a Java API for Android but nothing for pure Kotlin or Java desktop apps.
The reason behind wanting this is that stitch allows rules for which data to serve in a collection based on specific user data like a owner_id for example. It might be possible with a Kotlin wrapped over the stitch JavaScript API but I thought I might ask if its in the plan for KMongo first.
There is no support planned for now. However I think it should be doable using https://github.com/mongodb/stitch-android-sdk (it seems that there is also a "pure java" version you can use in this sdk - org.mongodb:stitch-server-sdk:version)
val conf = StitchAppClientConfiguration.Builder().run {
//with this line you should enable the KMongo object mapping support ->
withCodecRegistry( ClassMappingType.codecRegistry(BsonUtils.DEFAULT_CODEC_REGISTRY))
build()
}
val client = Stitch.initializeAppClient("<clientId>",conf)
Of course there is no extension defined for RemoteMongoCollection but you can add them using KMongo source code... ;)
HTH
What sort of things would need to be implemented to make the package usable? Could I follow the async or coroutines code to get an idea for what to make? I guess I need a bit of guidance on this matter
I would follow these steps:
-
Add these dependencies org.mongodb:stitch-server-sdk:4.2.1 org.litote.kmongo:kmongo:3.10.0
-
Use the code in the previous comment to insert and retrieve simple data with RemoteDataCollection using this doc: https://docs.mongodb.com/stitch/mongodb/mobile/build-sync/ . This should work (but I have not tested).
-
You can add extensions on the Sync interface ( mongodb.com/stitch-sdks/java/4/com/mongodb/stitch/android/services/mongodb/remote/Sync.html ) as it is done in KMongo: https://github.com/Litote/kmongo/blob/master/kmongo-core/src/main/kotlin/org/litote/kmongo/MongoCollections.kt .
HTH