ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - robert-cronin/kstitch: An object oriented toolkit for MongoDB Stitch in KotlinJS
An object oriented toolkit for MongoDB Stitch in KotlinJS - robert-cronin/kstitch
Visit Site

GitHub - robert-cronin/kstitch: An object oriented toolkit for MongoDB Stitch in KotlinJS

GitHub - robert-cronin/kstitch: An object oriented toolkit for MongoDB Stitch in KotlinJS

Awesome Kotlin Badge Download Build Status License

KStitch

A KotlinJS Toolkit for the MongoDB Stitch API. This tool kit will also support an ODM (Object Document Mapper) in the future, watch this space!

Heavily inspired by KMongo: https://github.com/Litote/kmongo

Getting Started

Development

You can explore the source code either by browsing this repo or downloading KStitch from GitHub:

git clone https://github.com/fortytwoapps/kstitch.git

Installing

To setup KStitch and start using it in your project, add these lines to build.gradle:

repositories {
    maven { url = "https://dl.bintray.com/robert-cronin/fortytwoapps" }
}

dependencies {
    implementation "fortytwoapps:kstitch:4.9.0"
}

Usage

To start using KStitch in your project, simply import like this:

import com.fortytwoapps.kstitch.*

If you are familiar with the MongoDB Stitch JavaScript API, you can still use the Kotlin in much the same way:

Initializing and logging in:
import com.fortytwoapps.kstitch.browser.*

fun main(args: Array<String>){
    // Initialize default app client
    Stitch.initializeDefaultAppClient('<your-client-app-id>')
    
    // Login anonymously
    val client = Stitch.initializeDefaultAppClient('<your-client-app-id>')
    client.auth.loginWithCredential(AnonymousCredential())
        .then {user -> 
            console.log("Logged in as anonymous user with id ${user.id}")
        }
}
Calling a function:
client.callFunction("echoArg", ["Hello world!"])
    .then { echoedResult ->
        console.log("Echoed result: $echoedResult")
    }

Note: this requires a function called echoArg to be defined in the Stitch UI that looks like this:

exports = function(arg) {
  return {arg: arg};
};

BSON and Extended JSON

KStitch now comes with BSON support:

import com.fortytwoapps.kstitch.bson.ObjectID

val newId = ObjectID()

ODM Functionaltiy

Define a Kotlin class and use it in Stitch!

class User(
        var _id: ObjectID = "",
        var adminUser: Boolean = false,
        var email: String = "",
        var fullName: String = "",
        var age: Int = 18,
        var customFunction: Code = Code("console.log('Hello World')")
)

val mongoClient = client.getRemoteServiceClient("<your-service-name>")
val userDatabase = mongoClient.db("user")
val userDataCollection = userDatabase.collection<User>("userData")

val specificUser: User = userDataCollection.find(UserData::_id eq ObjectID("5e13f16fb3de4f44ccb386e8")).await().firstOrNull()

val adminUserList: List<User> = userDataCollection.find(UserData::adminUser eq true).await()

Built With

Contributing

Feel free to contribute if you feel this toolkit is lacking for your application. Contributions are open.

Authors

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip goes to developers at MongoDB for developing the JavaScript Stitch API
  • Template for this readme came from PurpleBooth

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory