Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 1.38 KB

File metadata and controls

50 lines (39 loc) · 1.38 KB
ms.custom devx-track-js
ms.topic include
ms.date 03/04/2021

Install mongoose SDK

To connect and use your mongoDB on Azure Cosmos DB with JavaScript and mongoose, use the following procedure.

  1. Make sure Node.js and npm are installed.

  2. Create a Node.js project in a new folder:

    mkdir DataDemo && \
        cd DataDemo && \
        npm init -y && \
        npm install mongoose &&
        code .

    The command:

    • Creates a project folder named DataDemo
    • Changes the Bash terminal into that folder
    • Initializes the project, which creates the package.json file
    • Installs the SDK
    • Opens the project in Visual Studio Code

Use mongoose SDK to connect to MongoDB on Azure

  1. Copy the following JavaScript code into index.js:

  2. :::code language="javascript" source="~/../js-e2e//database/mongodb/index_mongoose.js" :::

  3. Replace YOUR-CONNECTION-STRING in the script with your resource connection string.

  4. Run the script.

    node index.js

    The results are:

    find all
    loop {"_id":"6019a68a6ecddc35d536c92c","name":"Joan Smith","job":"Developer","__v":0}
    loop {"_id":"6019a68e6ecddc35d536c92d","name":"Bob Jones","job":"Quality Assurance","__v":0}
    loop {"_id":"6019a6916ecddc35d536c92e","name":"Michelle Roberts","job":"Program Manager","__v":0}
    succeeded