我使用Cosmos db
创建了Mongo db api
。它适用于我的开发环境。但现在我想将它从开发复制到舞台和prod env。
所以我在azure portal上找不到任何选项。
非常感谢任何帮助。
答案 0 :(得分:0)
使用Azure Resource Manager模板,您可以轻松地自动部署和配置Azure资源。本教程介绍如何部署Web应用程序并自动配置Azure Cosmos DB帐户连接信息。
您可以使用here上的部署模板找到分步指南 如果这有帮助,请告诉我。
答案 1 :(得分:0)
软件依赖
从 https://www.python.org/downloads/windows/ 下载 Python
下载脚本文件夹并运行以下命令
创建种子数据 python 脚本文件为 seed_data.py
import json
import os
def get_employees():
employees = []
for file in os.listdir("Data\Employees"):
if file.endswith(".json"):
employeesFile = os.path.join("Data\Employees", file)
with open(employeesFile, encoding="utf8") as f:
employees.append(json.load(f))
return employees
def get_employee_details():
employee_details = {};
with open('SeedData/EmployeesDetails.json', encoding="utf8") as f:
employee_details = json.load(f)
return employee_details
from azure.cosmos import exceptions, CosmosClient, PartitionKey
import seed_data
import sys
# Initialize the Cosmos client
endpoint = sys.argv[1]
key = sys.argv[2]
database = sys.argv[3]
# Create cosmosClient
client = CosmosClient(endpoint, key)
# Create a database
database_name = database
database = client.create_database_if_not_exists(id=database_name)
# Create Employees Container
container_name = 'Employees'
container = database.create_container_if_not_exists(
id=container_name,
partition_key=PartitionKey(path="/id")
)
# Add see data to the Employees
employee_details_to_create = seed_data.get_employee_details()
container.upsert_item(body=employee_details_to_create)