Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sample JavaScript applications for Azure Cosmos DB API for MongoDB

License

NotificationsYou must be signed in to change notification settings

Azure-Samples/cosmos-db-mongodb-api-javascript-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A collection of## Examples

The following table shows all the numbered example directories and what each demonstrates:

DirectoryNameDescription
001-quickstartBasic CRUD OperationsComplete example showing database/collection creation, document insertion with upsert, point reads, indexing, and queries
101-client-connection-stringClient Connection OptionsDemonstrates connecting to Cosmos DB and displaying all MongoDB client connection options and settings
200-adminServer AdministrationShows how to get server information, check server status, and list all databases using admin commands
201-does-database-existDatabase Existence CheckChecks if a specific database exists by listing all databases and searching for a target database name
202-get-doc-countDocument CountingLists all databases and collections, then counts the number of documents in each collection
203-insert-docDocument InsertionDemonstrates inserting single documents withinsertOne() and multiple documents withinsertMany()
225-get-collection-indexesIndex ManagementShows how to retrieve and display all indexes on a collection
250-upsert-docDocument UpsertDemonstrates upsert operations (insert or update) usingupdateOne() with the upsert option
251-bulk_writeBulk OperationsShows how to perform multiple operations (insert, update) in a single bulk write operation
252-insert-manyBulk Data ImportDemonstrates importing data from JSON files usinginsertMany() for customers and products collections
275-findQuery OperationsComprehensive example of different find operations: point reads, queries by unique/non-unique values, find all, and pagination
280-aggregationAggregation PipelineContains two aggregation examples: calculating average prices by category and finding price ranges for bike subcategories
290-delete-docDocument DeletionShows how to delete single documents withdeleteOne() and multiple documents withdeleteMany()
299-drop-collectionCollection RemovalDemonstrates dropping/deleting entire collections from the database
300-drop-databaseDatabase RemovalShows how to drop/delete an entire database

Demo

To run any demo:

  1. Ensure Azure infrastructure is deployed (azd up)
  2. Load sample data (cd data && ./mongoimport.sh)
  3. Navigate to the desired sample directory
  4. Runnpm install && node index.jsdemonstrating how to use Azure Cosmos DB with the MongoDB API. This project is designed to run in a development container and deploy to Azure using the Azure Developer CLI.

Features

This project provides the following features:

  • Azure Cosmos DB MongoDB vCore integration samples
  • Development container with pre-configured environment
  • Azure Developer CLI (azd) deployment automation
  • AdventureWorks sample database seeding
  • Multiple JavaScript examples demonstrating CRUD operations

Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/Azure-Samples/cosmos-db-mongodb-api-javascript-samples.gitcd cosmos-db-mongodb-api-javascript-samples
  2. Open in development container:

    • Open the project in VS Code
    • When prompted, select "Reopen in Container" or useCtrl+Shift+P → "Dev Containers: Reopen in Container"
  3. Deploy to Azure:

    azd up

Quickstart

  1. Deploy infrastructure: Theazd up command provisions Azure Cosmos DB vCore and creates a root.env file with connection strings
  2. Load sample data: Navigate to the data directory and run the import script:
    cd data./mongoimport.sh
  3. Run samples: Each subdirectory contains a focused example:
    cd 001-quickstartnpm installnode index.js

Project Structure

  • Root.env: Contains Azure connection strings (auto-generated by azd)
  • /data: Contains AdventureWorks sample data and import scripts
  • /001-quickstart: Basic CRUD operations example
  • /275-find: Query and find operations example
  • /infra: Bicep templates for Azure infrastructure

Each sample directory references the root.env file for Azure Cosmos DB connection details.

Demo

The included samples demonstrate:

  1. Basic Operations (001-quickstart):

    • Connect to Azure Cosmos DB MongoDB vCore
    • Create database and collection
    • Insert, update, and query documents
  2. Advanced Queries (275-find):

    • Point reads with partition keys
    • Complex query operations
    • Index usage examples

To run any demo:

  1. Ensure Azure infrastructure is deployed (azd up)
  2. Load sample data (cd data && ./create-adventureworks.sh)
  3. Navigate to the desired sample directory
  4. Runnpm install && node index.js

Resources

About

Sample JavaScript applications for Azure Cosmos DB API for MongoDB

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp