From 0f1a9107daa0b0512624ba65b2d9af13c1eac7d7 Mon Sep 17 00:00:00 2001 From: William Wang Date: Thu, 24 Apr 2025 09:59:11 -0700 Subject: [PATCH] msg --- articles/cosmos-db/mongodb/vcore/data-api.md | 42 +++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/articles/cosmos-db/mongodb/vcore/data-api.md b/articles/cosmos-db/mongodb/vcore/data-api.md index 70b7aff615..1bbec97ae7 100644 --- a/articles/cosmos-db/mongodb/vcore/data-api.md +++ b/articles/cosmos-db/mongodb/vcore/data-api.md @@ -17,7 +17,24 @@ The Data API for Azure Cosmos DB for MongoDB vCore is an https interface that al ## Enabling Data API on MongoDB vCore -You can enable or disable this feature using the Azure CLI or an ARM template. Portal support will be added soon. +You can enable or disable this feature using the Azure Portal, Azure CLI or an ARM template. + +### Steps to enable Data API on Azure Portal + +1. **Go to Azure Portal** + - portal.azure.com + +2. **Go to your cluster** + +3. **Open the 'Features' blade** + +4. **Click on 'Data API'** + +5. **Click on 'Enable'** + +6. **Verify the result** + - Your 'Features' blade should now display 'Data API' as 'On'. + ### Steps to enable Data API on vCore cluster via ARM template @@ -86,7 +103,11 @@ Let's explore the supported operations, how to use the Data API. Use this command to perform an aggregation operation on a collection. ```bash -curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/aggregate -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database": "newDB", "collection": "newCollection", "pipeline": [{"$limit": 500}]}' +curl {cluster-name}.data.mongocluster.cosmos.azure.com:443/data/v1/action/aggregate -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database" : "testDB", "collection" : "testCollection", "pipeline" : [{"$limit" : 500}]}' --user "{username}:{password}" +``` + +```json +{ "documents" : [ { "_id" : { "$oid" : "680957492551581200c73bf8" }, "name" : "Sample Document", "createdAt" : { "$date" : { "$numberLong" : "1745442633506" } }, "tags" : [ "test", "mongo", "sample" ] } ] } ``` #### List databases @@ -94,8 +115,11 @@ curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action List all databases in the specified MongoDB vCore cluster. ```bash -curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/listDatabases -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{}' +curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/listDatabases -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{}' --user "{username}:{password}" +``` +```json +{ "databases" : [ { "name" : "testDB", "sizeOnDisk" : { "$numberInt" : "0" }, "empty" : false }, { "name" : "test", "sizeOnDisk" : { "$numberInt" : "0" }, "empty" : false } ], "totalSize" : { "$numberInt" : "0" }, "ok" : { "$numberDouble" : "1.0" } } ``` #### List collections @@ -103,7 +127,11 @@ curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action List all collections within a specific database. ```bash -curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/listCollections -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database": "newDB"}' +curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/listCollections -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database": "newDB"}' --user "{username}:{password}" +``` + +```json +{ "collections" : [ { "name" : "testCollection", "type" : "collection", "options" : { }, "info" : { "readOnly" : false, "uuid" : { "$binary" : { "base64" : "mNh96KepTm+NtLtALGxDiw==", "subType" : "04" } } }, "idIndex" : { "v" : { "$numberInt" : "2" }, "name" : "_id_", "key" : { "_id" : { "$numberInt" : "1" } } } } ] } ``` ### Get schema @@ -114,7 +142,11 @@ Retrieve the schema details of a specific database. Here's the formatted version for your .md file: ```bash -curl {cluster-name}.data.global.mongocluster.cosmos.azure.com:443/data/v1/action/getSchema -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database": "newDB"}' +curl {cluster-name}.data.mongocluster.cosmos.azure.com:443/data/v1/action/getSchema -H "Content-Type: application/ejson" -H "Accept:application/ejson" -d '{"database" : "testDB", "collection" : "testCollection"}' --user "{username}:{password}" +``` + +```json +{ "_id" : { "bsonType" : "objectId" }, "name" : { "bsonType" : "string" }, "createdAt" : { "bsonType" : "date" }, "tags" : { "bsonType" : "array" } } ``` ### Limitations