[GODRIVER-1732] As a developer, I would like to know the mongo version, so I can enable specific feature paths if available. Created: 29/Aug/20  Updated: 01/Sep/20  Resolved: 01/Sep/20

Status: Closed
Project: Go Driver
Component/s: API
Affects Version/s: 1.4.0, 1.3.7
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Matt Hartstonge Assignee: Divjot Arora (Inactive)
Resolution: Won't Do Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I would like an API that exposes the mongoDB version being worked with.
Currently, (as far as I know) there is no way to obtain the connected mongo version.

For example, for critical paths that require atomicity I would like the application to be able to know what version of mongo we are connected to so I can use the transaction API, or fall back to primary preferred, majority write.

I started hacking away with the transactions API which unexpectedly failed miserably with a mongo serialization error on Mongo 3.6. Coming from the mgo driver, which has a transaction API, I inadvertently expected the mongo-driver API to also work for 3.6.

 



 Comments   
Comment by Divjot Arora (Inactive) [ 01/Sep/20 ]

matt.hartstonge@gmail.com Great! If that's sufficient for your use case, I'm going to close out this ticket. Feel free to leave another comment or open a new ticket if you have any other questions.

– Divjot

Comment by Matt Hartstonge [ 01/Sep/20 ]

Hi @divjot, yes, I can build on top of that. �

https://github.com/matthewhartstonge/mongo-features

Comment by Divjot Arora (Inactive) [ 31/Aug/20 ]

Hi matt.hartstonge@gmail.com,

You can get this information by running the buildInfo command (https://docs.mongodb.com/manual/reference/command/buildInfo/) via the RunCommand API:

type BuildInfo struct {
    Version string
}
 
admin := client.Database("admin")
cmd := bson.D{{"buildInfo", 1})
 
var result BuildInfo
if err := admin.RunCommand(ctx, cmd).Decode(&result); err != nil {
    panic(err)
}
 
fmt.Printf("server version: %s\n", result.Version)

Does this satisfy your use case?

– Divjot

Comment by Matt Hartstonge [ 30/Aug/20 ]

Only way to get this information seems to be via the mongo shell:  https://docs.mongodb.com/manual/reference/method/db.version/

Generated at Thu Feb 08 08:37:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.