1
votes

I am trying to use JSON for application Configuration. I need some of the objects in the JSON to be dynamically crated(ex: Lookup from SQL database). It also needs to store the version history of the JSON file. Since I want to go back and forth to switch from old configuration to a new configuration version.

Initial thoughts were to put JSON on MongoDB and use placeholders for the dynamic part of the JSON object. Can someone give a guidance whether my thinking here is correct?(I am thinking of using JSON.NET for serialize/desiralize JSON object). Thanks in advance.

Edit:

Ex: lets assume we have 2 Environments. env1(v1.0.0.0) env2(v1.0.0.1)

**Env1** 

{

   id: env1 specific process id
   processname: process_name_specific_to_env1
   host: env1_specific_host_ip

   ...
   threads: 10(this is common across environments for V1.0.0.0 release)

}

**Env2** 

{

   id: env2 specific process id
   processname: process_name_specific_to_env2
   host: env2_specific_host_ip

   ...
   threads: 10(this is common across environments for V1.0.0.1 release)
   queue_size:15 (this is common across environments for V1.0.0.1 release)
}

what I want store is a common JSON file PER version. The idea is if I want to upgrade the version lets say env1 to 1.0.0.1(from 1.0.0.0), should be able to take the v1.0.0.1 of JSON config and fill the env specific data from SQL and generate a new JSON). This way when moving environments from one release to another do not have to re do configuration.

 ex: 1.0.0.0 JSON file
{

   id: will be dynamically filled in from SQL
   processname: will be dynamically filled in from SQL
   host: will be dynamically filled in from SQL

   ...
   threads: 10(this is common across environments for V1.0.0.0 release))


}

=> generate a new file for any environment when requested.

Hope I am being clear on what I am trying to achieve

1
Do you copy the result into another collection? Why can't you join those two configurations in your application code?Christian Strempfer

1 Answers

0
votes

As you said, you need some way to include the SQL part dynamically, that means manual joins in your application. Simple Ids referring to the other table should be enough, you don't need to invent a placeholder mechanism.

Choose which one is better for you:

MongoDB to SQL reference

MongoDB

{
     "configParamA": "123", // ID of SQL row
     "configParamB": "456", // another SQL ID
     "configVersion": "2014-11-09"
}

SQL to MongoDB reference

MongoDB

{
     "configVersion": "2014-11-09"
}

SQL

Just add a column with the configuration id, which is used in MongoDB, to every associated configuration row.