Working with MongoDB from Java

Working with MongoDB using Java Core isn't all that difficult either. Create a new Gradle project and install the mongodb driver and mongodb bson packages, as follows:

apply plugin: 'java-library' repositories {     jcenter() } dependencies {     implementation 'org.mongodb:mongo-java-driver:3.9.0'     implementation 'org.mongodb:bson:3.0.0’  }

Next, create a Plain Old Java Object (POJO) to represent our JSON document:

package com.packtpub.azure// [...]public class Person { @BsonId  private ObjectId Id; // [...]public ObjectId getId() { return id; }public Person setId(ObjectId id) { this.id = id; return this; }// [...]} 

Now, we can write the application:

public com.packtpub.azure; // [...] public class AzureMongoDBConsoleApp ...

Get Migrating Applications to the Cloud with Azure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.