Skip to main content
Version: v1.40.0

MongoDB

Overview​

Load the configuration from a MongoDB collection. This retriever is useful when you are using MongoDB and want to use a collection to store your configuration files.

MongoDB Collection Format​

If you use MongoDB to store your flags, you need a specific format to store your flags.

We expect the flag to be stored in JSON format as defined in the create flags section, but you should also add a new field called flag containing the name of the flag.

The retriever will read all the flags from the collection at once.

Example​

mongoDB flag format
{
"flag": "new-admin-access",
"variations": {
"default_var": false,
"false_var": false,
"true_var": true
},
"defaultRule": {
"percentage": {
"false_var": 70,
"true_var": 30
}
}
}

Configure the relay proxy​

To configure your relay proxy to use the MongoDB retriever, you need to add the following configuration to your relay proxy configuration file:

goff-proxy.yaml
# ...
retrievers:
- kind: mongodb
uri: mongodb://root:example@127.0.0.1:27017/
database: appConfig
collection: featureFlags
# ...
Field nameMandatoryTypeDefaultDescription
kindstringnoneValue should be mongodb.
This field is mandatory and describes which retriever you are using.
uristringnoneThis is the MongoDB URI used in order to connect to the MongoDB instance.
databasestringnoneName of the database where flags are stored.
collectionstringnoneName of the collection where flags are stored.

Configure the GO Module​

To configure your GO module to use the MongoDB retriever, you need to add the following configuration to your ffclient.Config{} object:

example.go
err := ffclient.Init(ffclient.Config{
PollingInterval: 3 * time.Second,
Retriever: &mongodbretriever.Retriever{
Collection: "featureFlags",
Database: "appConfig",
URI: "mongodb://root:example@127.0.0.1:27017/",
},
})
defer ffclient.Close()
FieldMandatoryDescription
CollectionName of the collection where your flags are stored
DatabaseName of the mongo database where the collection is located.
URIConnection URI of your mongoDB instance.