Skip to content

Commit

Permalink
expose ServerAPIVersion as a separate config option
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 16, 2022
1 parent 091e253 commit 7a6842c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions server/db/mongodb/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type configType struct {
TlsCertFile string `json:"tls_cert_file,omitempty"`
TlsPrivateKey string `json:"tls_private_key,omitempty"`
InsecureSkipVerify bool `json:"tls_skip_verify,omitempty"`

// The only version supported at this time is "1".
APIVersion mdbopts.ServerAPIVersion `json:"api_version,omitempty"`
}

// Open initializes mongodb session
Expand Down Expand Up @@ -170,13 +173,15 @@ func (a *adapter) Open(jsonconfig json.RawMessage) error {
a.maxMessageResults = defaultMaxMessageResults
}

opts.SetServerAPIOptions(mdbopts.ServerAPI(mdbopts.ServerAPIVersion1))

// Connection string URI overrides any other options configured earlier.
if config.Uri != "" {
opts.ApplyURI(config.Uri)
}

if config.APIVersion != "" {
opts.SetServerAPIOptions(mdbopts.ServerAPI(config.APIVersion))
}

// Make sure the options are sane.
if err = opts.Validate(); err != nil {
return err
Expand Down
9 changes: 6 additions & 3 deletions server/tinode.conf
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,19 @@

// MongoDB configuration.
"mongodb": {
// Connection string https://www.mongodb.com/docs/manual/reference/connection-string/
// Options configured with the connection string override any other options.
"uri": "",
// The only supported server API version is "1". May or maynot be needed depending on server version.
"api_version": "",

// Address(es) of MongoDB node(s): either a string or an array of strings.
"addresses": "localhost:27017",
// Name of the main database.
"database": "tinode",
// Name of replica set of mongodb instance. Remove this line to use a standalone instance.
// If replica_set is disabled, transactions will be disabled as well.
"replica_set": "rs0",
// Connection string https://www.mongodb.com/docs/manual/reference/connection-string/
// Options configured with the connection string override any other options.
"uri": "",

// Authentication options. Uncomment if auth is configured on your MongoDB.

Expand Down

0 comments on commit 7a6842c

Please sign in to comment.