{"id":26129486,"url":"https://github.com/mathworks-ref-arch/matlab-azure-cosmos-db","last_synced_at":"2026-02-10T09:04:39.085Z","repository":{"id":50077064,"uuid":"183264981","full_name":"mathworks-ref-arch/matlab-azure-cosmos-db","owner":"mathworks-ref-arch","description":"MATLAB Interface for Azure Cosmos DB","archived":false,"fork":false,"pushed_at":"2025-02-19T19:47:58.000Z","size":685,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T09:23:37.622Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathworks-ref-arch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-24T16:15:55.000Z","updated_at":"2025-02-19T19:48:02.000Z","dependencies_parsed_at":"2025-02-19T20:21:53.891Z","dependency_job_id":"4821a4eb-dfac-4f3d-9162-01f24445488b","html_url":"https://github.com/mathworks-ref-arch/matlab-azure-cosmos-db","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks-ref-arch%2Fmatlab-azure-cosmos-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks-ref-arch%2Fmatlab-azure-cosmos-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks-ref-arch%2Fmatlab-azure-cosmos-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathworks-ref-arch%2Fmatlab-azure-cosmos-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathworks-ref-arch","download_url":"https://codeload.github.com/mathworks-ref-arch/matlab-azure-cosmos-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248764774,"owners_count":21158151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-10T19:49:06.976Z","updated_at":"2026-02-10T09:04:39.035Z","avatar_url":"https://github.com/mathworks-ref-arch.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  MATLAB Interface *for Azure Cosmos DB*\n\nThis is a MATLAB® interface that connects to the Microsoft® Azure Cosmos DB™ service.\n\n## Requirements\n### MathWorks products\n* Requires MATLAB release R2019b or later\n* Database Toolbox\n  - The MongoDB API is supported directly in Database Toolbox R2019b and later, see below \n* Table API\n  - [MATLAB Interface *for Windows Azure Storage Blob*](https://github.com/mathworks-ref-arch/matlab-azure-blob) release 0.7.4 or later, This dependency has been deprecated and is not recommended.\n\n### 3rd party products\nTo build required JARs files for Gremlin, Table \u0026 SQL APIs:\n* Maven™\n* JDK 8\n* Microsoft® Azure Cosmos DB SDK for Java®\n\n## Getting started\n\nPlease refer to the documents in the [Documentation](Documentation/README.md) folder to get started. In particular, the Basic Usage guides which provide an overview for using the interface.\n\nAzure Cosmos DB is a globally distributed, multi-model database from Microsoft. Azure Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure's geographic regions. It offers throughput, latency, availability, and consistency guarantees with comprehensive service level agreements.\n\nThis interface supports four interfaces for Cosmos DB:\n  * MongoDB API\n    - This package is not required to access the Cosmos DB MonogDB interface in Database Toolbox R2019b or later. Support has been removed in release 0.2.0 and later. For convenience documentation relating to the Database Toolbox support has been [retained and updated](Documentation/BasicUsageMongoDB.md).\n  * SQL (DocumentDB) API\n  * Table API\n  * Gremlin API\n\nThe Cassandra API is currently not supported.\n\n## SQL API\n\nThis interface uses the original Azure Cosmos DB Sync Java SDK v2 for SQL API which supports synchronous operations.\n\nThe following are the main features of the interface:\n* Create, read, query \u0026 delete Databases\n* Create, read, query \u0026 delete Collections\n* Create, read, query, update \u0026 delete Documents\n* Create, read, query, update \u0026 delete Attachments\n* Create, read, query, execute \u0026 delete Stored Procedures\n* Create, read, query, execute \u0026 delete User Defined Functions\n* Create, read, query, \u0026 delete Triggers\n* Create, query and replace Offers\n\nThe follow code creates a database, assuming it does not already exist.\n```\n% create a document client\ndocClient = azure.documentdb.DocumentClient();\n\n% configure the database Id and standard request options\ndatabase = azure.documentdb.Database('mytestdatabase');\noptions = azure.documentdb.RequestOptions();\n\n% create the database using the client\ndocClient.createDatabase(database, options);\n\n% create a database link to read back the database to verify creation\ndatabaseLink = ['/dbs/',database.getId()];\nreadResponse = docClient.readDatabase(databaseLink, options);\ndatabaseResult = readResponse.getResource();\n\n% The following calls to the resulting database and the database object used\n% to create it should return the database Id: 'mytestdatabase'\ndatabaseResult.getId()\ndatabase.getId()\n\n% close the client when finished, note the database remains in existence\n% and will result in charges to the Azure account in question unless deleted\ndocClient.deleteDatabase(databaseLink, options);\ndocClient.close;\n```\n\n## Table API\nThe Table API supports the features provided by the Table interface provided by the [MATLAB Interface *for Windows Azure Storage Blob*](https://github.com/mathworks-ref-arch/matlab-azure-blob). This dependency has been deprecated and is not recommended. See: [https://github.com/mathworks-ref-arch/matlab-azure-services](https://github.com/mathworks-ref-arch/matlab-azure-services)\n\nFor example when an authenticated CloudStorageAccount object has been created it can be used to create a client which in turn can create table and list table contents as shown.\n\n```\n%% Create a *CloudTableClient* object and use it to create a new\n% *CloudTable* object which represents a table called *sampletable*.\n% A *CloudTable* object is required for most Table operations.\nazClient = az.getCloudTableClient();\ntableHandle = azure.storage.table.CloudTable(azClient,'sampletable');\ntableHandle.createIfNotExists();\n\n% To get a list of tables, call the *CloudTableClient.listTables()* method.\ntableList = azClient.listTables\n\ntableList =\n\n  1x14 CloudTable array with properties:\n\n    Parent\n    Name\n```\n\n## MongoDB API\nMongoDB API support requires the installation of the MathWorks Database Toolbox. The Database Toolbox Interface for MongoDB ships with the Database toolbox since R2019b. \n\nThe following sample code connects to a database and inserts some sample data.\n```\n%% Create connection to Cosmos DB Mongo API\n% Use valid values for myusername, mydatabasename, myusername \u0026 password\nconn = mongo(\"myusername.documents.azure.com\", 10255, \"mydatabasename\",...\n\"UserName\", \"myusername\",...\n\"Password\", \"sa\u003cREDACTED\u003eEwg==\",...\n\"AuthMechanism\", \"SCRAM_SHA_1\", \"SSLEnabled\", true);\n\n% Create a collection\nmyCollectionName = 'MongoTestCollection';\nconn.createCollection(myCollectionName);\n\n% Check if there are anything in the collection already, there should not be\ndataCount = count(conn, myCollectionName);\n\n% Create some sample data\nLastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};\nAge = [38;43;38;40;49];\nSmoker = logical([1;0;1;0;1]);\nHeight = [71;69;64;67;64];\nWeight = [176;163;131;133;119];\nBloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];\nT = table(LastName,Age,Smoker,Height,Weight,BloodPressure);\n\n% Put the data into MongoDB from the table T\ndata = conn.insert(myCollectionName, T);\n\n% Close the connection when finished\nconn.close();\n```\n\n## Gremlin API\n\nThe Gremlin API allows you to create and manage an  Microsoft® Azure Cosmos DB™ Gremlin (graph) API account. You will need a Gremlin (Graph) database account with Azure Cosmos DB before you get started. Details on creating a Graph database account can be found [here](https://docs.microsoft.com/en-us/azure/cosmos-db/create-graph-java#create-a-database-account).\n\nThe next step would be to configure the credentials for the database account. The credentials need to be placed at the folder location `MATLAB/Gremlin/config` for the API to access them. Please see `gremlindb.yml.template` for reference. Details on accessing credentials from the Azure Cosmos DB Gremlin API account can be found [here](https://docs.microsoft.com/en-us/azure/cosmos-db/create-graph-java#update-your-connection-information).\n\nOnce the credentails have been put in place, follow the instructions provided within [Installation](Documentation/Installation.md) to install the API for use. Run the `startup.m` file within `Software/MATLAB/Gremlin` once you have completed the installation steps.\n\nThe following sections contain sample code for getting started with the API. A more detailed example is available at [GettingStarted](Documentation/BasicUsageGremlin.md).\n\n### Create a MATLAB client for Azure Cosmos DB Gremlin API\nThe MATLAB class `GremlinClient` reads credentials from the YAML file located at `MATLAB/Gremlin/config` and returns a MATLAB client object as follows:\n\n```\ngClient = azure.gremlin.GremlinClient('gremlindb.yml')\n```\n\n### Construct a Gremlin query\nQueries need to be defined as strings in MATLAB. You can pass either a single query or multiple queries using a cell array.\n\n```\n%  Write a query to drop any existing graph in the sample database\n%  The following is a single query string passed within a MATLAB cell array\n\nqueries = {\"g.V().drop()\"};\n\n%  For multiple queries you can pass comma seperated query strings within the cell array.\n```\nNote: If a script or query is to be executed repeatedly with slightly different arguments, consider concatenating queries rather than dynamically produced strings, see [basic usage](Documentation/BasicUsageGremlin.md).\n\n### Submit a Gremlin query to Azure Cosmos DB Graph\nOne can submit small queries synchronously using the `submit()` method. Once the client finishes writing all requests, query response is returned within an object `ResultSet`. One can use the method `get()` to return any resultant dataset pertaining to the query.\n\n```\n% Submit queries synchronously\n\nresultSet = gClient.submit(queries);\n\n% Get query results\n\nresponse = resultSet.get;\n```\n\n### Creating and submitting multiple GREMLIN queries.\nUse a cell array containing the multiple queries to submit requests to the Gremlin Server.\nIn the below example, multiple queries are submitted to feed data in the Graph database. Multiple graph vertices with properties such as `id`, `firstName`, `lastName`, `age` and `partitionKey` ar being created with the label `person` with the help of the Gremlin step `addV`.\n\n```\nqueries  = {\"g.addV('person').property('id', 'thomas').property('firstName', 'Thomas').property('age', 44).property('pk', 'pk')\",...\n    \"g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39).property('pk', 'pk')\",...\n    \"g.addV('person').property('id', 'ben').property('firstName', 'Ben').property('lastName', 'Miller').property('age', 55).property('pk', 'pk')\",...\n    \"g.addV('person').property('id', 'robin').property('firstName', 'Robin').property('lastName', 'Wakefield').property('age', 22).property('pk', 'pk')\"};\n```\n\n### Submitting Asynchronous requests.\nOne can submit multiple or large queries asynchronously using the `submitAsync` method, where the query results can be gathered once the client completes writing all queries.\n\n```\n% Resultset of type completablefurture is returned\ncompletableFutureResults = gClient.submitAsync(queries);\n\n% Get final Response post asynchronous call completion\nresponse = completableFutureResults.get;\n```\n\n### Closing the client connection to the Database\n```\ngClient.close()\n\n```\n## Supported Products\n\nMathWorks Products (http://www.mathworks.com)\n1.  MATLAB (R2017b or later)\n2.  MATLAB Compiler and Compiler SDK (R2017b or later)\n3.  MATLAB Production Server (R2017b or later)\n4.  MATLAB Parallel Server (R2017b or later)\n\nThis package is primarily tested on Ubuntu™ 20.04 and Windows™ 10.\n\n## License\nThe license for the MATLAB Interface *for Azure Cosmos DB* is available in the [LICENSE.md](LICENSE.md) file in this GitHub repository. This package uses certain third-party content which is licensed under separate license agreements. See the [SQL/pom.xml](Software/SQL/Java/pom.xml) \u0026 [Gremlin/pom.xml](Software/Gremlin/Java/pom.xml) files for third-party software downloaded at build time.    \n\n## Enhancement Request\nProvide suggestions for additional features or capabilities using the following link:   \nhttps://www.mathworks.com/products/reference-architectures/request-new-reference-architectures.html\n\n## Support\nEmail: `mwlab@mathworks.com`\n\n[//]: #  (Copyright 2019-2023, The MathWorks, Inc.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks-ref-arch%2Fmatlab-azure-cosmos-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathworks-ref-arch%2Fmatlab-azure-cosmos-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathworks-ref-arch%2Fmatlab-azure-cosmos-db/lists"}