A simple Kotlin class to use to connect to a MongoDB collection.

Overview

mongodb-kotlin

A simple Kotlin class to use to connect to a MongoDB collection.

Once you have created a MongoDB project, choose Build a Database:

image

Next, choose the free "Shared" option and scroll all the way down:

image

Expand "Cluster Name" and pick a cool name for your cluster. I'll leave it as the default. Now, we need to create a seperate username and password so our code can access this database.

image

Click create user once you're done and be sure to select Cloud Environment as your connection location.

image

Lastly, add "0.0.0.0/0" as an IP Address.

image

At the bottom, click Finish and Close. Once it's ready, click Browse Collections and Add My Own Data. image

You'll need to pick a name for your database and it's collection. Don't forget them. Now click overview and then CONNECT:

image image

Choose Connect your application:

image

All you will need from this is the bit of text from the "@" symbol to where it says "mongodb.net" (it should look like "clusterName.random stuff"):

image

Now you're ready to write some code.

When you create an instance of the MongoDB class, put in the username and password we just made:

MongoDB(LoginInfo("myUsername", "mySecurePassword"), "cluster", "MyDatabaseName")

"cluster" is that string we found in the very last step. "MyDatabaseName" is the one you chose along with the collection name. Check the Example.kt for more information.

Note

At the time of writing, the correct pom dependancy for Maven is (the version may change in the future):

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.4.0</version>
</dependency>
You might also like...
Kotlin compiler plugin that allows class delegation to be dynamic like property delegations

kotlin-dynamic-delegation Kotlin compiler plugin that allows class delegation to be dynamic like property delegations. The plugin is working in progre

Kotlin Example of how to organize your code using MVC and some patterns seen in class
Kotlin Example of how to organize your code using MVC and some patterns seen in class

Kotlin Example of how to organize your code using MVC and some patterns seen in class

Minimalistic class proxy creator for Kotlin

reflektion Minimalistic class proxy creator for Kotlin. Reflektion allows you to create an implementation of an interface you provide containing proxy

BindsAdapter is an Android library to help you create and maintain Adapter class easier via ksp( Kotlin Symbol Processing).

BindsAdapter BindsAdapter is an Android library to help you create and maintain Adapter class easier via ksp( Kotlin Symbol Processing). Installation

An extensive collection of Kotlin Android Utils
An extensive collection of Kotlin Android Utils

An extensive collection of Kotlin Android Utils This library contains small helper functions used throughout almost all of my other projects. The goal

KoltinPulsar - A collection of experiments using Kotlin with Apache Pulsar

Some Experiments of using Kotlin and Apache Pulsar This is a collection of exper

Third application for Big Brain Kotlin book, will be pokemon collection app
Third application for Big Brain Kotlin book, will be pokemon collection app

Big Brain Kotlin : Application #3 - PokemonHurddle Third application for Big Brain Kotlin book, will be pokemon collecting app 11285 Pokemon and becom

Collection of various algorithms in mathematics, computer science etc implemented in Kotlin for educational purposes.

The Kotlin Algorithms Implementation of different algorithms and data structures using Kotlin lang Overview The repository is a collection of open-sou

A deep learning based mobile application for the multi-class classification of pneumonia into three categories via Chest X-rays

PneumoniaClassifier A deep learning based mobile application for the multi-class classification of pneumonia into three categories via Chest X-rays. W

Owner
null
Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

mohsen 21 Dec 3, 2022
An android app using Mongodb for logistics tracking system.

DeliveryGo An android application for logistics tracking. Used technology Kotlin: In this project kotlin is used to code the full application on Andro

Joysankar Majumdar 1 Mar 5, 2022
Template to accelerate the creation of new apps using Spring Boot 3, MongoDB & GraphQL.

Template to accelerate the creation of new apps using Spring Boot 3, MongoDB & GraphQL.

André Ramon 1 Feb 13, 2022
User Authentication ( Compose Ktor Server MongoDB)

Utilising Security in android for Authentication and Authorization for Android I would be using mongo db to perform all basic operations no need for f

Michael Enoma 0 May 2, 2022
A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server

dadb Blog Post: Our First Open-Source Project A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server de

mobile.dev 791 Dec 20, 2022
The behavior of Couchbase Lite C when attempting to connect to a Sync Gateway

This demo demonstrates the behavior of Couchbase Lite C when attempting to connect to a Sync Gateway, while the process has various numbers of file de

Gabriel Terwesten 0 Nov 29, 2021
Kafka Connect connector for CØSMOS based blockchains.

CØSMOS Kafka Connector Kafka Connect connector for CØSMOS based blockchains. Purpose The Kafka Connect CØSMOS Source connector is a Kafka connector us

OKP4 – Open Knowledge Protocol For 6 Nov 23, 2022
Kafka Connect JSLT Single Message Transform

This is an implementation of the Kafka Connect SMT interface to offer transformation capabilities using the Schibsted JSLT library.

willhaben 2 May 25, 2022
Therapeutic is a platform to help easily connect patients or generally anyone struggling to get through tough times with motivating content and professional therapists.

Therapeutic Apk - https://github.com/develNerd/Therapeutic/blob/main/androidApp/release/androidApp-release6.apk Therapeutic is a Kotlin Mobile Multipl

Isaac Akakpo 1 Nov 23, 2022
Kotlin & Java class for gRPC client

jvm-minter-grpc-class Kotlin & Java class for gRPC client Use @TODO Разное Добавление git subtree add --prefix node-grpc-gateway https://github.com/Mi

Aleksey Kukhnovets 2 May 26, 2022