'Right' way to create indexes?

263 views
Skip to first unread message

Mongo Rookie

unread,
Mar 20, 2013, 9:30:43 AM3/20/13
to mongoo...@googlegroups.com
Just read the following from the mongoose docs on indexes:

When your application starts up, Mongoose automatically calls ensureIndex for each defined index in your schema. While nice for development, it is recommended this behavior be disabled in production since index creation can cause a significant performance impact. Disable the behavior by setting the autoIndex option of your schema to false.

 This leaves me a little puzzled.  When I am creating a new collection I have been just writing a schema and putting the indexes directly into the schema.  In this case my collection does not even exist before that step.

Am I supposed to somehow create my collections outside mongoose and ensure that I set indexes appropriately? Or do I just leave indexes off and start inserting a bunch of data, only to write something that will go in and create the indexes later?

I could not find a good example of how to implement index creation the 'right' way.

Any ideas?

Aaron Heckmann

unread,
Mar 21, 2013, 8:08:01 PM3/21/13
to mongoo...@googlegroups.com
Good question.

Creation of collections is not an issue. Creation of indexes on large-ish / hot data sets might be.

For development, letting mongoose create indexing for you is convenient. In production, you want to think about the potential impact of creating a new index on your data set and when it might be the best time to do so. Ask yourself things like: Is it is a large data set? Am I under heavy load during certain times of the day? On very large data sets, it might even be necessary to add the index using a technique similar to how you perform "rolling upgrades" of your cluster, where you step down a node / take it offline / add the index / bring it back online etc. Just depends how big/hot your dataset is and when you might have less load on it.



--
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
 
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Aaron


Reply all
Reply to author
Forward
0 new messages