
20 Gremlin Query Examples for Azure Cosmos DB (Practical Cheat Sheet)
Why a Gremlin Cheat Sheet? The Gremlin query language is powerful but has a steep learning curve — especially on Azure Cosmos DB, where partition keys, RU costs, and unsupported steps add complexity that standard TinkerPop tutorials don't cover. This post gives you 20 copy-paste-ready queries organized by category, with Cosmos DB-specific tips for each one. All examples use an e-commerce graph with product , person , and category vertices, but the patterns apply to any domain. Creating Data 1. Add a Vertex with Partition Key g.addV('product').property('id', 'prod-001').property('category', 'electronics').property('name', 'Wireless Headphones').property('price', 79.99).property('inStock', true) Every vertex needs an id (unique within the partition) and the partition key property. If your container's partition key is /category , you must include it as a property. Without it, Cosmos DB assigns a random partition and your queries become expensive cross-partition fan-outs. 2. Add an Edge g.
Continue reading on Dev.to Tutorial
Opens in a new tab



