services | platforms | author |
---|---|---|
cosmos-db |
java |
arramac |
Azure Cosmos DB is a globally distributed multi-model database. One of the supported APIs is the MongoDB API, which provides a document model and support for client drivers in many platforms. This sample shows you how to use the Azure Cosmos DB with the MongoDB API to store and access data from a Java application.
-
Before you can run this sample, you must have the following prerequisites:
- An active Azure account. If you don't have one, you can sign up for a free account. Alternatively, you can use the Azure Cosmos DB Emulator for this tutorial.
- JDK 1.7+ (Run
apt-get install default-jdk
if you don't have JDK) - Maven (Run
apt-get install maven
if you don't have Maven)
-
Then, clone this repository using
git clone [email protected]:azure-samples/azure-cosmosdb-mongodb-java-getting-started.git
-
Next, substitute the endpoint and authorization key in Program.java with your Cosmos DB account's values.
-
From a command prompt or shell, run
mvn package
to compile and resolve dependencies. -
From a command prompt or shell, run
mvn exec:java -D exec.mainClass=GetStarted.Program
to run the application.
The code included in this sample is intended to get you quickly started with a Java application that connects to Azure Cosmos DB with the MongoDB API.