“我正在使用 azure cosmosdb 和 mongodb api,我想知道如何检查 azure cosmosdb mongo api 中的数据库是否使用 cosmos 连接字符串启用了自动缩放。我使用 express.js 作为中间件框架。”
答案 0 :(得分:0)
获取此信息的一种可能方法是使用 @azure/cosmos
节点包。
import {CosmosClient} from '@azure/cosmos';
const endpoint = 'https://youraccountname.documents.azure.com';
const key = 'your account password';
const client = new CosmosClient({endpoint, key});
const databaseName = 'your database name';
const db = client.database(databaseName);
db.readOffer()
.then((response) => {
const offerDetails = response.resource;//This will have all the necessary information.
})
.catch((error) => {
console.log(error);
});
这是对具有自动缩放吞吐量模式的数据库之一的响应:
{
"resource":"dbs/XXXXXX==/",
"offerType":"Invalid",
"offerResourceId":"XXXXXX==",
"offerVersion":"V2",
"content":{
"offerThroughput":400,
"offerMinimumThroughputParameters":{
"maxThroughputEverProvisioned":4000,
"maxConsumedStorageEverInKB":0
},
"offerAutopilotSettings":{
"tier":0,
"maximumTierThroughput":0,
"autoUpgrade":false,
"autoUpgradePolicy":{
"throughputPolicy":{
"incrementPercent":10
}
},
"maxThroughput":4000
}
},
"id":"XXxX",
"_rid":"XXxX",
"_self":"offers/XXxX/",
"_etag":"\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"_ts":1625655292
}
您需要做的是检查 offerAutopilotSettings
下的 content
属性。仅当为数据库配置的吞吐量模式为“自动缩放”时才会出现这种情况
答案 1 :(得分:0)
var connection = mongoose.createConnection(
connectionString
(error, doc) => {
if (error) {
return res
.json({message: error}) }
}
);
connection.db.command({customAction: "GetDatabase"})
.then((data) => {res.json(data)})
.catch(error => {res.json(error)})
Output:
------
{
"database" : "test",
"provisionedThroughput" : 2000,
"autoScaleSettings" : {
"maxThroughput" : 20000
},
"ok" : 1
}
参考:https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-custom-commands#create-database 我们可以使用 Mongo API 在 comsos DB 中执行的所有其他功能