1 回答

TA貢獻1111條經驗 獲得超0個贊
我已經聯系了微軟的支持,這是他們的回復:
這是對具有時間點還原的帳戶的限制。必須使用唯一索引創建集合。
https://docs.microsoft.com/en-us/azure/cosmos-db/continuous-backup-restore-introduction
您可以使用這樣的命令創建具有已存在的唯一索引的集合(從Mongo外殼,或Robo3T或其他客戶端)
用于管理 Azure Cosmos DB 的 MongoDB API 中數據的 MongoDB 擴展命令|微軟文檔
例如:
db.runCommand({
customAction: "CreateCollection",
collection: "my_collection",
shardKey: "my_shard_key",
offerThroughput: 100,
indexes: [{key: {_id: 1}, name: "_id_1"}, {key: {a: 1, b: 1}, name:"a_1_b_1", unique: true} ]
})
所以現在我的代碼看起來像這樣:
func Collection(db *mongo.Database, c string, indices []bson.M) *mongo.Collection {
ctx, cls := context.WithTimeout(context.Background(), time.Second * 15)
defer cls()
if cursor, _ := db.ListCollectionNames(ctx, bson.M{"name": c}); len(cursor) < 1 {
cmd := bson.D{{"customAction", "CreateCollection"}, {"collection", c}}
if indices != nil {
cmd = append(cmd, bson.E{Key: "indexes", Value: indices})
}
res := db.RunCommand(ctx, cmd)
if res.Err() != nil {
log.Fatal(res.Err())
}
}
return db.Collection(c)
}
- 1 回答
- 0 關注
- 99 瀏覽
添加回答
舉報