Strategy to copy specific document values from dev to production

Hello! I’m hoping someone has come up with a good strategy for something I’m looking to do, and can only assume someone else has looked to do the same previously.

We do development locally, then deploy changes to a staging server, and later to production. While developing, we may create various changes to documents, but let’s use one example… configuration information which may be updated by site managers. Here’s a (fake) example:

{
    "_id" : ObjectId("12345"),
    "font" : "Arial",
    "color" : "#FFF",
    "cotact" : "John Doe"
}

Once in production, these may be changed. Let’s say John Doe leaves, and someone updates the contact to be Jane Doe, and Jane prefers Helvetica so now production looks like.

{
    "_id" : ObjectId("12345"),
    "font" : "Helvetica",
    "color" : "#FFF",
    "cotact" : "Jane Doe"
}

In the meantime, a developer is changing that document (and maybe other similar ones) for new work, and their local document ends up like:

{
    "_id" : ObjectId("98765"),
    "font" : "Arial",
    "color" : "#FFF",
    "cotact" : "John Doe",
    "phoneNumber": '555-555-5555'
}

When putting the latest code into production, I’d like whatever default values were created for this new development (here, ‘phoneNumber’) to be updated in staging, and later production. BUT, the other data in the document should not be updated so as not to lose the user’s changes or other things in staging. Ultimately, I’d want production to look like this:

{
    "_id" : ObjectId("12345"), 
    "font" : "Helvetica",
    "color" : "#FFF",
    "cotact" : "Jane Doe",
[... any other new data added by other changes ...]
    "phoneNumber": '555-555-5555'
}

Is there a good, somewhat automatic, way to get this done? Updating by hand can be tedious, and prone to human error, especially if there are many changes. How are others handling these sorts of changes?

Thanks for any input!

Hi @K_M and welcome in the MongoDB Community :muscle: !

I guess you could code something based on Change Streams and implement your rules in there.

Cheers,
Maxime.

Hello, and thanks. I was looking at that, but not sure if it’d complicate things. I’m not totally up to speed on Change Streams, but my understanding is a developer would then have to capture the changes in the local environment and “some action” would have to happen at that time (I could be wrong). Since many changes could happen in a local DB during development, I think I’d need the final product, so to speak.

Actually, now that I think of it, it’s more like a “diff” operation between dev/production, and rules based on what’s different.

Thanks, you got me a good idea of an avenue to look down.

1 Like

You could use the change events from the change stream to build the “diff” incrementally as you develop. Could be a lead but as I’m not in the project, it’s hard to judge :slight_smile:.

Cheers,
Maxime.