Extracting/Capturing the mongodb equivalent of SQL DDL

1,184 views
Skip to first unread message

D Boyd

unread,
Dec 16, 2010, 12:56:52 PM12/16/10
to mongodb-user
Thought I would ask the group how they handle this task in their
environments.

In the SQL world one frequently create scripts (DDL) to create tables,
indexes, constraints, etc.

In mongdb the schemaless nature makes the idea of scripts for tables
and relational constraints a
non-issue.

However, things like indexes and sharding configurations for
collections are something one
would potentially want to capture off of a development/prototype
system and then configuration
manage over for a production system.

In SQL world there are neat little tools that will reverse engineer
all that stuff from an existing database.
Anything like that for Mongodb?

So how do folks do this with mongo:

1. Have code (e.g. console javascript) that is run on the collection
to create indexes, etc.?
2. Just dump/import the db then delete the data?

Or some other way.

Basically, for my production system I just want to pre-create all my
collections and indexes and I am
looking to see what the community currently views as best practice.

dwight_10gen

unread,
Dec 16, 2010, 8:33:42 PM12/16/10
to mongodb-user
you can save indexes with:

db.system.indexes.find()

and replay that (recreate) with;

db.system.insert(...) for each one.

createCollection() in the shell can be used to explicitly create a
collection, but normally this is unnecessary as they will implicitly
create on the first insert.

dwight_10gen

unread,
Dec 16, 2010, 8:34:24 PM12/16/10
to mongodb-user
i would suggest writing a script to set up your sharding
configuration. typically one does this from the mongo shell, so you
can do this in a re-runnable manner by making a .js file and giving it
to the mongo shell on its command line.


On Dec 16, 12:56 pm, D Boyd <db...@data-tactics.com> wrote:
Reply all
Reply to author
Forward
0 new messages