| ms.custom | devx-track-js |
|---|---|
| ms.topic | include |
| ms.date | 03/04/2021 |
To connect and use your mongoDB on Azure Cosmos DB with JavaScript and mongodb, use the following procedure.
-
Make sure Node.js and npm are installed.
-
Create a Node.js project in a new folder:
mkdir DataDemo && \ cd DataDemo && \ npm init -y && \ npm install mongodb && code .
The command:
- Creates a project folder named
DataDemo - Changes the Bash terminal into that folder
- Initializes the project, which creates the
package.jsonfile - Installs the SDK
- Opens the project in Visual Studio Code
- Creates a project folder named
-
In Visual Studio Code, create a
bulk_insert.jsfile. -
Download the MOCK_DATA.csv file and place it in the same directory as
bulk_insert.js. -
Copy the following JavaScript code into
bulk_insert.js::::code language="javascript" source="~/../js-e2e//database/mongodb/bulk_insert_mongodb.js" :::
-
Replace the following in the script with your resource information:
- YOUR_RESOURCE_PRIMARY_CONNECTION_STRING
-
Run the script.
node bulk_insert.js
-
In Visual Studio Code, create a
index.jsfile. -
Copy the following JavaScript code into
index.js::::code language="javascript" source="~/../js-e2e/database/mongodb/index_mongodb.js" :::
-
Replace the following in the script with your resource information:
- YOUR_RESOURCE_PRIMARY_CONNECTION_STRING
-
Run the script.
node index.js