How to export Mongo db schema?

7,193 views
Skip to first unread message

Will.yao

unread,
Feb 24, 2010, 7:59:46 AM2/24/10
to mongodb-user
As in mysql, after creating a db, I can export the db schema for
backup.
In mongodb, how can I do that?

Eliot Horowitz

unread,
Feb 24, 2010, 8:11:05 AM2/24/10
to mongod...@googlegroups.com
Since there isn't a schema you can't export that. You can use
mongodump to backup the whold database though

> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en
> .
>

Erix Yao

unread,
Feb 24, 2010, 8:17:31 AM2/24/10
to mongod...@googlegroups.com
what if I want to create an index on a db and the db fails? 
Since there's no meta data for the db I had, I lost all the indexes...

2010/2/24 Eliot Horowitz <elioth...@gmail.com>

Eliot Horowitz

unread,
Feb 24, 2010, 8:21:20 AM2/24/10
to mongod...@googlegroups.com
Mongodump will export system.indexes along with the regular data. So all the indexes will be recovered. 

Will.yao

unread,
Feb 24, 2010, 8:22:32 AM2/24/10
to mongodb-user
what if I just want the meta data for a specific db?


On 2月24日, 下午9时21分, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> Mongodump will export system.indexes along with the regular data. So  
> all the indexes will be recovered.
>

> On Feb 24, 2010, at 8:17 AM, Erix Yao <yao.e...@gmail.com> wrote:
>
> > what if I want to create an index on a db and the db fails?
> > Since there's no meta data for the db I had, I lost all the indexes...
>

> > 2010/2/24 Eliot Horowitz <eliothorow...@gmail.com>


> > Since there isn't a schema you can't export that. You can use  
> > mongodump to backup the whold database though
>

Erix Yao

unread,
Feb 24, 2010, 8:26:42 AM2/24/10
to mongodb-user
firstly we have only one application using one component along with mongodb, and now the common component needs to be migrated to another application, how can I copy the db meta without the data for another application?

Eliot Horowitz

unread,
Feb 24, 2010, 8:26:52 AM2/24/10
to mongod...@googlegroups.com
All the meta data is in system. So you can look at those collections.

Erix Yao

unread,
Feb 24, 2010, 8:28:45 AM2/24/10
to mongod...@googlegroups.com
you mean export the system db to another server ?



For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

Erix Yao

unread,
Feb 24, 2010, 8:31:30 AM2/24/10
to mongod...@googlegroups.com
I really think we can make this migration a little more normalized, I mean, I can get the job done with a easier way.
Am I still thinking in the way of MySQL?

Eliot Horowitz

unread,
Feb 24, 2010, 8:33:41 AM2/24/10
to mongod...@googlegroups.com
No, system. Namespaces

But what meta data are you referring to?  The only real meta data is indexes and the general way people handle indexes is calling ensureIndex in their code which will create the index if necesarry.    So I think that is a better strategy 

Eliot Horowitz

unread,
Feb 24, 2010, 8:41:57 AM2/24/10
to mongod...@googlegroups.com
Yeah, I think things are a bit different with mongo

Is the code written for this app yet or are you just planning?  

Erix Yao

unread,
Feb 24, 2010, 8:45:55 AM2/24/10
to mongod...@googlegroups.com
It's written and the component using mongodb are going to be used for another app. so I'm planning for this migration.


2010/2/24 Eliot Horowitz <elioth...@gmail.com>

Eliot Horowitz

unread,
Feb 24, 2010, 8:49:28 AM2/24/10
to mongod...@googlegroups.com
So what meta data does that component need?  If any, how was it added in the first place?

Erix Yao

unread,
Feb 24, 2010, 8:50:19 AM2/24/10
to mongod...@googlegroups.com
I noticed that you say the indexes is always created in application code if needed.
Does this mean all the indexes are temporary for one operation and can be created with no performance penalty?
Two many indexes will not affect the performance, right?

Erix Yao

unread,
Feb 24, 2010, 8:53:21 AM2/24/10
to mongod...@googlegroups.com
all the indexes . creating the db is simple. and after that , we created some indexes in shell

I am just thinking, what if mongodb is widely used in my department and all the indexes or some other meta data for db must be created in the shell by hand?

the meta data for this migration is not too much, so I can handle that by hand


2010/2/24 Eliot Horowitz <elioth...@gmail.com>

Eliot Horowitz

unread,
Feb 24, 2010, 9:03:18 AM2/24/10
to mongod...@googlegroups.com
No, not at all
Notice the name i used is ensureIndex. That means create if not there.
It is often good to keep in application code so it lives in the same place and is versione together. 

Mitch Pirtle

unread,
Feb 24, 2010, 10:20:04 AM2/24/10
to mongod...@googlegroups.com
As a side note, I always use some sort of scm for projects - git,
subversion, whatever - and log all data/schema changes so everyone
else working on the project can have the same environment.

This is a good idea, regardless of whether you're using MongoDB or
MySQL etc. Could be as simple as writing a shell script that looped
through a text file containing all your database commands (ensure
index and so on). So in the event someone already had an existing
database, they could "replay" those changes to remain consistent with
someone who was doing a full import from a mongoexport file - which
also should be under revision control.

-- Mitch

dprutean

unread,
May 16, 2017, 5:43:24 AM5/16/17
to mongodb-user, yao....@gmail.com
There is a tool called DbSchema which can represent the MongoDb structure.
 It scans few documents from each collection and detect a 'schema'.
The amazing stuff about this tool is that it can show this schema as diagrams. 
Reply all
Reply to author
Forward
0 new messages