getVersion returns the version of mongod or mongos instance.
(ctx context.Context)
| 258 | |
| 259 | // getVersion returns the version of mongod or mongos instance. |
| 260 | func (d *Driver) getVersion(ctx context.Context) (string, error) { |
| 261 | database := d.client.Database(bytebaseDefaultDatabase) |
| 262 | var commandResult bson.M |
| 263 | command := bson.D{{Key: "buildInfo", Value: 1}} |
| 264 | if err := database.RunCommand(ctx, command).Decode(&commandResult); err != nil { |
| 265 | return "", errors.Wrap(err, "cannot run buildInfo command") |
| 266 | } |
| 267 | version, ok := commandResult["version"] |
| 268 | if !ok { |
| 269 | return "", errors.New("cannot get version from buildInfo command result") |
| 270 | } |
| 271 | v, ok := version.(string) |
| 272 | if !ok { |
| 273 | return "", errors.New("cannot convert version to string") |
| 274 | } |
| 275 | return v, nil |
| 276 | } |
| 277 | |
| 278 | // isDatabaseExist returns true if the database exists. |
| 279 | func (d *Driver) isDatabaseExist(ctx context.Context, databaseName string) (bool, error) { |
no test coverage detected