Re: [casbah] mongo migrations - something like liquibase?

2,117 views
Skip to first unread message

Wes Freeman

unread,
Jul 5, 2012, 4:01:38 PM7/5/12
to mongodb-ca...@googlegroups.com
I think I just answered your stackoverflow question related... I've just been rolling my own--I use Salat/Casbah myself, so I too get stuck wanting my models to match the schema. I haven't heard of such a tool that will automatically make schema changes for you. Considering the flexibility (and the potential complexity of the schemas) of mongo, it's probably just easier to write your own conversion tool each time (rather than mapping fields in a tool).

If you've only got a few thousand it should only take a moment to update them all. It gets bad when you get to the millions, especially if your update grows the documents significantly, because the padding factor won't be enough for them to stay in the same spot on disk.

At some point in the scale of >1M docs, it's going to be better to make the app code work for both style schemas, so you can slowly migrate them (or never migrate them, if the new schema doesn't contain critical fields, going forward).

Wes

On Thu, Jul 5, 2012 at 2:15 PM, RB Dev <rbh...@gmail.com> wrote:
Hello,

Isn't a casbah question, but thought this might be a good group to ask.

How are people addressing Mongo document change migrations?  

Example: let's say I have a case class Track(name: String, measure: Map[String, Double]) with a few thousand documents in the collection.  But, we need to update to case case Track(name: String, measure: Map[String, Map[String, Double]])

Before I roll my own, wondering if there is something like liquibase for Mongo? 


-Todd




RB Dev

unread,
Jul 5, 2012, 4:13:49 PM7/5/12
to mongodb-ca...@googlegroups.com
Great thoughts, thanks.

I'm thinking something like Mongeez - https://github.com/secondmarket/mongeez 

Wes Freeman

unread,
Jul 6, 2012, 1:27:31 PM7/6/12
to mongodb-ca...@googlegroups.com
Sounds like a good idea--scripting your changes in some sort of version control so you can reproduce them. I've been just building a class called "InsertX" or "RemoveX" or "ConvertX" that I leave in my app code and only use for the conversion, which is a bit rougher than mongeez's idea, but it accomplishes the same task.

Ideally you'll only need to run that sort of thing a few times between dev and production, unless you're building a product that you're distributing and need to migrate them all as they upgrade to the next version (hmm, that's something to think about).

Wes

Lukasz S

unread,
Aug 5, 2014, 4:17:47 AM8/5/14
to mongodb-ca...@googlegroups.com
Hi,

Mongeez uses eval() method which requires Mongo's root user to be executed.
Better solution (if you want to use simpler user with read/write permissions) is to use mongobee: https://github.com/mongobee/mongobee
Tool is early version but is quite simple
Reply all
Reply to author
Forward
0 new messages