indexing - is there any way to restore predefined schema to mongoDB? -


i'm beginner mongodb. want know there way load predefined schema mongodb? ( example cassandra use .cql file purpose)

if there is, please intruduce document structure of file , way restoring.

if there not, how can create index 1 time when create collection. think wrong if create index every time call insert method or run program.

p.s: have multi-threaded program every thread insert , update mongo collection. want create index 1 time.

thanks.

to create index on collection need use ensureindex command. need call once create index on collection.

if call ensureindex repeatedly same arguments, first call create index, subsequent calls have no effect.

so if know indexes you're going use database, can create script call command.

an example insert_index.js file creates 2 indexes colla , collb collections:

db.colla.ensureindex({ : 1}); db.collb.ensureindex({ b : -1}); 

you can call shell this:

mongo --quiet localhost/dbname insert_index.js 

this create indexes on database named dbname on localhost. it's worth noticing if database and/or collections not yet created, create both database , collections you're adding indexes.

edit

to clarify little bit. mongodb schemaless can't restore it's schema. can create indexes , collections (by using createcollection helper).


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -