Build a Node.js app with Azure Cosmos DB’s API for MongoDB

Shweta Nayak

A new video series on using Node.js with Azure Cosmos DB API for MongoDB is now available on the Azure Cosmos DB YouTube channel. The series walks through how we built the backend functionalities of a demo application “Cosmos Bookstore”. The application is a books catalog that uses React for the front-end layer, NodeJS and Express for the back-end layer, and Azure Cosmos DB (with the API for MongoDB) as the database.  

screenshot of the Cosmos Books demo application showing seven book covers in two rows
Cosmos Bookstore demo application


If you are a Node.js developer who is new to Azure Cosmos DB or its API for MongoDB, this series is for you. While building the demo app, you’ll learn about: 

  • Connecting to the database & the client configuration 
  • Reads & Queries 
  • Sorting & Indexing 
  • Updates
  • Using different operators 
  • Checking RU cost of the previous operation 
  • Regex queries 
  • Aggregation pipelines 
  • Azure Search integration 

The series has five videos:  

Part 1 - Connecting & Reading  

This introduction talks about the application stack, the sample dataset used, and its schema. We will walk through the code structure and the backend modules, then initiate a common database client that gets used by all the backend modules. We then demonstrate the usage of MongoDB find(), cursor for reading the list of books from the database. Post this, we achieve pagination with skip() and limit(). Lastly, we demonstrate the usage of projection, indexing, and sorting.


Part 2 – Query conditions & Updates 

In this video, we use different MongoDB query conditions and operators to allow filtering options in the book catalog. We demonstrate the use of the $gt operator for comparison, in order to filter books by rating. We use $in array expression to filter books by their book format. findOne() command is used to get the book details. Lastly, we demonstrate the use of updateOne() command with array operators $push, $unset and $pull to add or remove comments on a book.


Part 3 – Regex, Aggregation pipeline & Request charge 

In this part, we focus on slightly more advanced use cases. We demonstrate the use of regex and aggregation pipeline to achieve typeahead search in the genres filter of the books catalog. We use $unwind, $match and $group stages in the aggregation pipeline. Lastly, we demonstrate how to check the request charge of the last operation. This is an explicit functionality in the Azure Cosmos DB API for MongoDB. 


Text search functionality in the Azure Cosmos DB API for MongoDB must be achieved in integration with Azure Cognitive Search. This part walks through how to set up the search service, import data and create the search index. We then use the search index to provide basic text search functionality in the application. 


Part 5 – Azure Search integration – Search options 

This last part covers advanced search functionalities. This includes pagination with text search result, as well as select and orderby. We also demonstrate filtering using Azure search operators like gt, and search.ismatch. This allows the filters and sort options available in the application to be functional against the search indexer data too.

We hope you find this video series helpful. Drop a comment below if you have ideas for other scenarios and capabilities to add to this demo application. 

About Azure Cosmos DB

Azure Cosmos DB is a fast and scalable distributed NoSQL database, built for modern application development. Get guaranteed single-digit millisecond response times and 99.999-percent availability, backed by SLAsautomatic and instant scalability, and open-source APIs for MongoDB and Cassandra. Enjoy fast writes and reads anywhere in the world with turnkey data replication and multi-region writes.

Watch our Get Started videos on YouTube and explore ways to dev/test free.


Discussion is closed. Login to edit/delete existing comments.

    • Shweta NayakMicrosoft employee 0

      Thanks for letting us know Abhishek. This has been fixed, the repo should be accessible now.

Feedback usabilla icon