user2638955
user2638955

Reputation: 91

In Mongodb, How can I Index on field(s) in collection(s) in secondary node(replica-set) only

Is there any way to selectively index on secondary replica-set collection fields only as I don't need those index on primary's collection?

Eg. I have Product collection with Product-Category as field. I don't want to index this field on primary, I only want index on replica-set secondary as I will be reading data only from secondary.

Upvotes: 5

Views: 1857

Answers (1)

Peter Jaffe
Peter Jaffe

Reputation: 311

I realize this is an old thread, but I was recently digging around on the same topic. I want to run data reporting tools against my live data, and I assume I'll want different indexes for that, and but I don't want to introduce them in a way that impacts the performance of my primary nodes that are serving application requests (since more indexes increase memory consumption and I believe can impact write performance in a way that would be visible to the consuming application depending on the chosen MongoDB Write Concern).

I came across two things:

  1. This feels like a hack to me, but some people recommend using a hidden secondary that is configured to never become a primary, and they temporarily take it out of the replica set, add additional indexes, and then add it back into the replica set - Different indexes on different replica set members

  2. And that stackoverflow posting also referenced the following open MongoDB enhancement request "Allow different indexes on replica set p=0 nodes" https://jira.mongodb.org/browse/SERVER-3664. Please vote it up!

Pete

Upvotes: 5

Related Questions