You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/create-mongodb-flask.md
+17-23Lines changed: 17 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,21 +21,13 @@ ms.date: 12/26/2018
21
21
> *[Golang](create-mongodb-golang.md)
22
22
>
23
23
24
-
Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. You can quickly create and query document, key/value, and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Cosmos DB.
25
-
26
-
This quickstart guide uses the following [Flask example](https://github.com/Azure-Samples/CosmosDB-Flask-Mongo-Sample) and demonstrates how to build a simple To-Do Flask app with the [Azure Cosmos DB Emulator](local-emulator.md) and the Azure Cosmos DB's API for MongoDB.
24
+
In this quickstart, you use an Azure Cosmos DB for Mongo DB API account or the Azure Cosmos DB Emulator to run a Python Flask To-Do web app cloned from GitHub. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
27
25
28
26
## Prerequisites
29
27
30
-
- Download the [Azure Cosmos DB Emulator](local-emulator.md). The emulator is currently only supported on Windows. The sample shows how to use the sample with a production key from Azure, which can be done on any platform.
31
-
32
-
- If you don’t already have Visual Studio Code installed, you can quickly install [VS Code](https://code.visualstudio.com/Download) for your platform (Windows, Mac, Linux).
33
-
34
-
- Be sure to add Python Language support by installing one of the popular Python extensions.
35
-
1. Select an extension.
36
-
2. Install the extension by typing `ext install` into the Command Palette `Ctrl+Shift+P`.
37
-
38
-
The examples in this document use Don Jayamanne's popular and full featured [Python Extension](https://marketplace.visualstudio.com/items?itemName=donjayamanne.python).
28
+
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). Or [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) without an Azure subscription. Or, you can use the [Azure Cosmos DB Emulator](local-emulator.md).
29
+
-[Python 3.6+](https://www.python.org/downloads/)
30
+
-[Visual Studio Code](https://code.visualstudio.com/Download) with the [Python Extension](https://marketplace.visualstudio.com/items?itemName=donjayamanne.python).
39
31
40
32
## Clone the sample application
41
33
@@ -69,7 +61,7 @@ Now let's clone a Flask-MongoDB app from GitHub, set the connection string, and
69
61
70
62
This step is optional. If you're interested in learning how the database resources are created in the code, you can review the following snippets. Otherwise, you can skip ahead to [Run the web app](#run-the-web-app).
71
63
72
-
The following snippets are all taken from the app.py file and uses the connection string for the local Azure Cosmos DB Emulator. The password needs to be split up as seen below to accommodate for the forward slashes that cannot be parsed otherwise.
64
+
The following snippets are all taken from the *app.py* file and uses the connection string for the local Azure Cosmos DB Emulator. The password needs to be split up as seen below to accommodate for the forward slashes that cannot be parsed otherwise.
73
65
74
66
* Initialize the MongoDB client, retrieve the database, and authenticate.
75
67
@@ -101,29 +93,31 @@ The following snippets are all taken from the app.py file and uses the connectio
101
93
102
94
3. Then set the environment variable for the Flask app with `set FLASK_APP=app.py`, `$env:FLASK_APP = app.py` for PowerShell editors, or `export FLASK_APP=app.py` if you are using a Mac.
103
95
104
-
4. Run the app with `flask run` and browse to [http://127.0.0.1:5000/](http://127.0.0.1:5000/).
96
+
4. Run the app with `flask run` and browse to *http:\//127.0.0.1:5000/*.
105
97
106
98
5. Add and remove tasks and see them added and changed in the collection.
107
99
108
100
## Create a database account
109
101
102
+
If you want to test the code against a live Azure Cosmos DB account, go to the Azure portal to create an account.
If you want to test the code against a live Cosmos Account, go to the Azure portal to create an account and get your connection string information. Then copy it into the app.
108
+
To test the code against the live Azure Cosmos DB account, get your connection string information. Then copy it into the app.
115
109
116
-
1. In the [Azure portal](https://portal.azure.com/), in your Cosmos account, in the left navigation click **Connection String**, and then click **Read-write Keys**. You'll use the copy buttons on the right side of the screen to copy the Username, Password, and Host into the Dal.cs file in the next step.
110
+
1. In your Azure Cosmos DB account in the Azure portal, in the left navigation select **Connection String**, and then select **Read-write Keys**. You'll use the copy buttons on the right side of the screen to copy the username, connection string, and password.
117
111
118
-
2. Open the **app.py** file in the root directory.
112
+
2. Open the *app.py* file in the root directory.
119
113
120
-
3. Copy your **username** value from the portal (using the copy button) and make it the value of the **name**in your **app.py** file.
114
+
3. Copy your **username** value from the portal (using the copy button) and make it the value of the **name**in your *app.py* file.
121
115
122
-
4. Then copy your **connection string** value from the portal and make it the value of the MongoClient in your **app.py** file.
116
+
4. Then copy your **connection string** value from the portal and make it the value of the **MongoClient**in your *app.py* file.
123
117
124
-
5. Finally copy your **password** value from the portal and make it the value of the **password**in your **app.py** file.
118
+
5. Finally copy your **password** value from the portal and make it the value of the **password**in your *app.py* file.
125
119
126
-
You've now updated your app with all the info it needs to communicate with Cosmos DB. You can run it the same way as before.
120
+
You've now updated your app with all the info it needs to communicate with Azure Cosmos DB. You can run it the same way as before.
127
121
128
122
## Deploy to Azure
129
123
@@ -139,7 +133,7 @@ When deploying to Azure, you should remove your application keys and make sure t
139
133
140
134
You then need to add your MONGOURL, MONGO_PASSWORD, and MONGO_USERNAME to the application settings. You can follow this [tutorial](https://docs.microsoft.com/azure/app-service/configure-common#configure-app-settings) to learn more about Application Settings in Azure Web Apps.
141
135
142
-
If you don't want to create a fork of this repo, you can also click the deploy to Azure button below. You should then go into Azure and set up the application settings with your Cosmos DB account info.
136
+
If you don't want to create a fork of this repo, you can also selectthe**Deploy to Azure** button below. You should then go into Azure and set up the application settings with your Azure Cosmos DB account info.
<img src="https://azuredeploy.net/deploybutton.png" alt="Click to Deploy to Azure">
@@ -158,7 +152,7 @@ If you don't want to create a fork of this repo, you can also click the deploy t
158
152
159
153
## Next steps
160
154
161
-
In this quickstart, you've learned how to create a Cosmos account and run a Flask app. You can now import additional data to your Cosmos database.
155
+
In this quickstart, you learned how to create an Azure Cosmos DB for Mongo DB API account, and use the Azure Cosmos DB Emulator to run a Python Flask To-Do web app cloned from GitHub. You can now import additional data to your Azure Cosmos DB account.
162
156
163
157
> [!div class="nextstepaction"]
164
158
> [Import MongoDB data into Azure Cosmos DB](mongodb-migrate.md)
In this quickstart, you'll use the Azure Cosmos DB API for Mongo DB and Java SDK to create a console web app. Azure Cosmos DB allows you to quickly create and query document, key/value and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Cosmos DB.
26
-
27
-
This quickstart demonstrates how to create a Cosmos account with [Azure Cosmos DB's API for MongoDB](mongodb-introduction.md). You'll then build and deploy a console app built using the [MongoDB Java driver](https://docs.mongodb.com/ecosystem/drivers/java/).
25
+
In this quickstart, you create and manage an Azure Cosmos DB for MongoDB API account from the Azure portal, and add data by using a Java SDK app cloned from GitHub. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
28
26
29
27
## Prerequisites
30
-
31
-
Before you can run this sample, you must have the following prerequisites:
32
-
*[Install the JDK for Azure and Azure Stack JDK version 8](https://aka.ms/azure-jdks)
33
-
* Maven (Run `apt-get install maven` if you don't have Maven)
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). Or [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) without an Azure subscription. You can also use the [Azure Cosmos DB Emulator](https://aka.ms/cosmosdb-emulator) with the connection string `.mongodb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:10255/admin?ssl=true`.
29
+
-[Java Development Kit (JDK) version 8](https://www.azul.com/downloads/azure-only/zulu/?&version=java-8-lts&architecture=x86-64-bit&package=jdk).
30
+
-[Maven](https://maven.apache.org/download.cgi). Or run `apt-get install maven` to install Maven.
@@ -73,7 +68,9 @@ Now let's clone an app from GitHub, set the connection string, and run it. You'l
73
68
74
69
This step is optional. If you're interested in learning how the database resources are created in the code, you can review the following snippets. Otherwise, you can skip ahead to [Update your connection string](#update-your-connection-string).
75
70
76
-
The following snippets are all taken from the Program.java file.
71
+
The following snippets are all taken from the *Program.java* file.
72
+
73
+
This console app uses the [MongoDB Java driver](https://docs.mongodb.com/ecosystem/drivers/java/).
77
74
78
75
* The DocumentClient is initialized.
79
76
@@ -109,9 +106,9 @@ The following snippets are all taken from the Program.java file.
109
106
110
107
Now go back to the Azure portal to get your connection string information and copy it into the app.
111
108
112
-
1. From the Account, select **Quick Start**, select **Java**, then copy the connection string to your clipboard.
109
+
1. From your Azure Cosmos DB account, select **Quick Start**, select **Java**, then copy the connection string to your clipboard.
113
110
114
-
2. Open the `Program.java` file, replace the argument to the MongoClientURI constructor with the connection string. You've now updated your app with all the info it needs to communicate with Azure Cosmos DB.
111
+
2. Open the *Program.java* file, replace the argument to the MongoClientURI constructor with the connection string. You've now updated your app with all the info it needs to communicate with Azure Cosmos DB.
115
112
116
113
## Run the console app
117
114
@@ -131,7 +128,7 @@ You can now use [Robomongo](mongodb-robomongo.md) / [Studio 3T](mongodb-mongoche
131
128
132
129
## Next steps
133
130
134
-
In this quickstart, you've learned how to create a Cosmos account, create a collection and run a console app. You can now import additional data to your Cosmos database.
131
+
In this quickstart, you learned how to create an Azure Cosmos DB API for Mongo DB account, add a database and container using Data Explorer, and add data using a Java console app. You can now import additional data to your Cosmos database.
135
132
136
133
> [!div class="nextstepaction"]
137
134
> [Import MongoDB data into Azure Cosmos DB](mongodb-migrate.md)
This quickstart demonstrates how to use an existing MongoDB app written in Node.js and connect it to your Azure Cosmos database, which supports MongoDB client. In other words, it is transparent to the application that the data is stored in a Cosmos database.
26
-
27
-
Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. You can quickly create and query document, key/value, and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Cosmos DB.
28
-
29
-
When you are done, you will have a MEAN application (MongoDB, Express, Angular, and Node.js) running on [Cosmos DB](https://azure.microsoft.com/services/cosmos-db/).
30
-
31
-

25
+
In this quickstart, you create and manage an Azure Cosmos DB for Mongo DB API account by using the Azure Cloud Shell, and with a MEAN (MongoDB, Express, Angular, and Node.js) app cloned from GitHub. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
32
26
27
+
## Prerequisites
28
+
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). Or [try Azure Cosmos DB for free](https://azure.microsoft.com/try/cosmosdb/) without an Azure subscription. You can also use the [Azure Cosmos DB Emulator](https://aka.ms/cosmosdb-emulator) with the connection string `.mongodb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:10255/admin?ssl=true`.
29
+
-[Node.js](https://nodejs.org/), and a working knowledge of Node.js.
30
+
-[Git](https://git-scm.com/downloads).
31
+
- If you don't want to use Azure Cloud Shell, [Azure CLI 2.0+](/cli/azure/install-azure-cli).
If you choose to install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
37
-
38
-
## Prerequisites
39
-
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
In addition to Azure CLI, you need [Node.js](https://nodejs.org/) and [Git](https://www.git-scm.com/downloads) installed locally to run `npm` and `git` commands.
43
-
44
-
You should have working knowledge of Node.js. This quickstart is not intended to help you with developing Node.js applications in general.
45
-
46
35
## Clone the sample application
47
36
48
37
Run the following commands to clone the sample repository. This sample repository contains the default [MEAN.js](https://meanjs.org/) application.
@@ -67,6 +56,8 @@ Run the following commands to clone the sample repository. This sample repositor
67
56
68
57
## Run the application
69
58
59
+
This MongoDB app written in Node.js connects to your Azure Cosmos DB database, which supports MongoDB client. In other words, it is transparent to the application that the data is stored in an Azure Cosmos DB database.
60
+
70
61
Install the required packages and start the application.
71
62
72
63
```bash
@@ -76,9 +67,11 @@ npm start
76
67
```
77
68
The application will try to connect to a MongoDB source and fail, go ahead and exit the application when the output returns "[MongoError: connect ECONNREFUSED 127.0.0.1:27017]".
78
69
79
-
## Log in to Azure
70
+
## Sign in to Azure
71
+
72
+
If you choose to install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI].
80
73
81
-
If you are using an installed Azure CLI, login to your Azure subscription with the [az login](/cli/azure/reference-index#az-login) command and follow the on-screen directions. You can skip this step if you're using the Azure Cloud Shell.
74
+
If you are using an installed Azure CLI, signin to your Azure subscription with the [az login](/cli/azure/reference-index#az-login) command and follow the on-screen directions. You can skip this step if you're using the Azure Cloud Shell.
82
75
83
76
```azurecli
84
77
az login
@@ -88,7 +81,7 @@ az login
88
81
89
82
If you are using an installed Azure CLI, check to see if the `cosmosdb` component is already installed by running the `az` command. If `cosmosdb` is in the list of base commands, proceed to the next command. You can skip this step if you're using the Azure Cloud Shell.
90
83
91
-
If `cosmosdb` is not in the list of base commands, reinstall [Azure CLI](/cli/azure/install-azure-cli).
84
+
If `cosmosdb` is not in the list of base commands, reinstall [Azure CLI](/cli/azure/install-azure-cli).
In this quickstart, you've learned how to create a Cosmos account, create a collection and run a console app. You can now import additional data to your Cosmos database.
244
+
In this quickstart, you learned how to create an Azure Cosmos DB MongoDB API account using the Azure Cloud Shell, and create and run a MEAN.js app to add users to the account. You can now import additional data to your Azure Cosmos DB account.
252
245
253
246
> [!div class="nextstepaction"]
254
247
> [Import MongoDB data into Azure Cosmos DB](mongodb-migrate.md)
0 commit comments