Last active
March 31, 2017 15:52
-
-
Save kyoro1/e62a085c3fe019c3a09fa54ff183b0c7 to your computer and use it in GitHub Desktop.
Azure documentDBのdocumentをpydocumentdbで抽出してみる ref: http://qiita.com/kyoro1/items/51410dad7f41fa0e07b4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install pydocumentdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
## library setting | |
import pydocumentdb.document_client as document_client | |
## 各種設定 | |
HOST = 'abc_server.documents.azure.com:443/' | |
DATABASE_ID = 'abc_database' | |
COLLECTION_ID = 'abc_collection' | |
MASTER_KEY = 'abc_api' | |
# documentDb client instance作成 | |
client = document_client.DocumentClient(HOST, {'masterKey': MASTER_KEY}) | |
# database/collection定義 | |
database_definition = {'id': DATABASE_ID } | |
collection_definition = { 'id': COLLECTION_ID } | |
## DB接続を定義 | |
databases = list(client.QueryDatabases({ | |
'query': 'SELECT * FROM root r WHERE r.id=@id', | |
'parameters': [ | |
{ 'name':'@id', 'value': database_definition['id'] } | |
] | |
})) | |
db = databases[0] | |
## Collectionを定義 | |
collections = list(client.QueryCollections( | |
db['_self'], | |
{ | |
'query': 'SELECT * FROM root', | |
'parameters': [ | |
{ 'name':'@id', 'value': collection_definition['id'] } | |
] | |
})) | |
collection = collections[0] | |
## Documentsを格納 | |
### Documentsを入れとく箱 | |
list = [] | |
### 1つずつ入れていきましょー | |
for doc in client.ReadDocuments(collection['_self']): | |
list.append(doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment