catspeake
我已经联系了微软的支持,这是他们的回复:这是对具有时间点还原的帐户的限制。必须使用唯一索引创建集合。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)}