We're happy to announce that you can now do more within MongoDB queries and types in Azure Cosmos DB. With the latest service deployment, we have made the following improvements in MongoDB API in Azure Cosmos DB.
- MongoDB aggregation pipeline support (preview)
- Unique index support
- MongoDB wire protocol version 5 support, used in MongoDB 3.4 (preview)
MongoDB aggregation pipeline
In MongoDB, the aggregation pipeline enables developers to create more sophisticated queries and manipulate data by combining multiple aggregation ‘stages’ together, thus enabling them to do more data processing on the server side before the results get returned to the client. The data can be filtered, sorted, and prepared for use, eliminating the need to transfer large amounts of data over the wire only to reduce it to a manageable size in the client code.
For example, the following aggregation pipeline finds the records in the Volcanos collection, matching only the ones in the United States, grouping records by the volcano type, collecting the volcano elevation for each one, and counting the number of records matched, all in a single query:
There are many other powerful aggregation, data wrangling, and analytics scenarios that could take advantage of aggregation pipeline capabilities. To learn about every aggregation pipeline construct and other MongoDB syntax constructs currently supported by Azure Cosmos DB, please see MongoDB feature support.
Support for the aggregation pipeline is in now in public preview and can be enabled on the Preview Features page of any MongoDB API account in the Azure portal.
Unique Indexes and Index Management
Azure Cosmos DB indexes every field in documents that are written to the database by default. Unique indexes ensure that a specific field doesn’t have duplicate values across all documents in a collection, similar to the way uniqueness is preserved on the default “_id” key. Now you can create custom indexes in Azure Cosmos DB by using the createIndex command, including the ‘unique’ constraint.
Unique indexes are available for all MongoDB API accounts.
MongoDB wire protocol (version 5)
Azure Cosmos DB implements the MongoDB wire protocol, which enables its MongoDB API to be compatible with most MongoDB applications and tools. The MongoDB wire protocol version that Azure Cosmos DB supports is now version 5. With this change, the wire protocol support is on par with MongoDB 3.4. This enables Azure Cosmos DB to be used by a wider range of applications that take advantage of the capabilities of wire protocol version 5. For instance, applications using Azure Cosmos DB with MongoDB API can now take advantage of the types defined by the BSON specification, such as Decimal128.
This capability is now in public preview and can be enabled on the Preview Features page of any MongoDB API account in the Azure portal.
Try it now
Since these enhancements are a service-side change, you do not need to download anything or make any changes on the client side. The only thing you need to do is enable the aggregation pipeline public preview or MongoDB wire protocol (version 5) features via the switches in the Azure portal:
You can get started with the Azure Cosmos DB MongoDB API by creating an account and connecting it by using the credentials in from Connection String page in the Azure portal.
We continuously evaluate use cases that could take advantage of these new capabilities. We hope that these improvements to the MongoDB API unlock more scenarios and use cases for your applications. Please let us know at firstname.lastname@example.org if you have any feedback on these new capabilities.
You can try Azure Cosmos DB for free today, no sign up or credit card required. Stay up-to-date on the latest Azure Cosmos DB news and features by following us on Twitter #CosmosDB and @AzureCosmosDB.
– Your friends at Azure Cosmos DB
Source: Azure Blog Feed