getPrimaryShard return the primary shard name of specified db
(c *mongo.Client, dbName string)
| 341 | |
| 342 | // getPrimaryShard return the primary shard name of specified db |
| 343 | func getPrimaryShard(c *mongo.Client, dbName string) (string, error) { |
| 344 | filter := bson.D{{"_id", fmt.Sprintf("%s", dbName)}} |
| 345 | var result bson.M |
| 346 | err := c.Database(DbConfig).Collection(CollDatabases).FindOne(context.Background(), filter).Decode(&result) |
| 347 | if err != nil { |
| 348 | return "", fmt.Errorf("find db:%s in config.databses failed: %v", dbName, err) |
| 349 | } |
| 350 | primaryShard, ok := result["primary"].(string) |
| 351 | if !ok { |
| 352 | return "", fmt.Errorf("unexpected doc:%+v", result) |
| 353 | } |
| 354 | return primaryShard, nil |
| 355 | } |
| 356 | |
| 357 | func moveChunkIfNeeded(dstC *mongo.Client, dbName, collName string, hasHashed bool) error { |
| 358 | // get new uuid for namespace |
no test coverage detected