Skip to content

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 ​

json
{
    // highlight-next-line
    "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:

yaml
# ...
retrievers:
  - kind: mongodb
    uri: mongodb://root:example@127.0.0.1:27017/
    database: appConfig
    collection: featureFlags
# ...
Field nameMandatoryTypeDefaultDescription
kindYesstringnoneValue should be mongodb.
This field is mandatory and describes which retriever you are using.
uriYesstringnoneThis is the MongoDB URI used in order to connect to the MongoDB instance.
databaseYesstringnoneName of the database where flags are stored.
collectionYesstringnoneName 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:

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

Released under the MIT License.