Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions DocumentDBGetStarted.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import pydocumentdb;
import pydocumentdb.document_client as document_client

config = {
'ENDPOINT': 'https://FILLME.documents.azure.com',
'MASTERKEY': 'FILLME',
'DOCUMENTDB_DATABASE': 'db',
'DOCUMENTDB_COLLECTION': 'coll'
};
}

# Initialize the Python DocumentDB client
client = document_client.DocumentClient(config['ENDPOINT'], {'masterKey': config['MASTERKEY']})
client = document_client.DocumentClient(
config['ENDPOINT'],
{'masterKey': config['MASTERKEY']}
)

# Create a database
db = client.CreateDatabase({ 'id': config['DOCUMENTDB_DATABASE'] })
Expand All @@ -22,7 +24,11 @@
}

# Create a collection
collection = client.CreateCollection(db['_self'], { 'id': config['DOCUMENTDB_COLLECTION'] }, options)
collection = client.CreateCollection(
db['_self'],
{ 'id': config['DOCUMENTDB_COLLECTION'] },
options
)

# Create some documents
document1 = client.CreateDocument(collection['_self'],
Expand All @@ -32,7 +38,8 @@
'Cloud Service': 0,
'Virtual Machine': 0,
'name': 'some'
})
}
)

document2 = client.CreateDocument(collection['_self'],
{
Expand All @@ -41,16 +48,17 @@
'Cloud Service': 0,
'Virtual Machine': 0,
'name': 'some'
})
}
)

# Query them in SQL
query = { 'query': 'SELECT * FROM server s' }
query = { 'query': 'SELECT * FROM server' }

options = {}
options['enableCrossPartitionQuery'] = True
options['maxItemCount'] = 2

result_iterable = client.QueryDocuments(collection['_self'], query, options)
results = list(result_iterable);
results = list(result_iterable)

print(results)