2

I have multiple large MongoDB collections. I have to make a change in one collection that should automatically make the corresponding changes in all the mongoDB collections.

In other words I have to sync all my MongoDB collection so that if I make change in one, it should reflect that change automatically in all the other MongoDB collections.

What should I do to achieve it ?

Community
  • 1
  • 1

1 Answers1

0

I do not think there is a way to do it. As I have attended MongoDB course they have repeatedly said that, if we duplicate the values across multiple collections then it is our responsibility to maintain the DB in its consistent state.

Another point is, why do we have to replicate the data: Only possible reason is for performance enhancements.

RajaM
  • 11
  • 1
  • 6
  • And if you are not replicating the data but some data is dependent on the data being inserted in the collections then also we have to depend on the logic to insert into other collections. – RajaM Apr 15 '14 at 07:43
  • Some of the fields in the collection are dependent on other collections like the foreign key concept in RDBMS. So if i have to make change in one collection, how it should be reflected in other collections to maintain consistency in database. – Rahul Mittal Apr 16 '14 at 05:54
  • I don't think it is possible to have dependent collections updated based on some insertion of document in another collection. We will have to do sync all data through program. Nothing is automatic. Here is a very nice post through which it is very nicely and cleanly explained when should you look for implementing the linking vs embedding. http://stackoverflow.com/questions/5373198/mongodb-relationships-embed-or-reference. In your case you have implemented linking and you want auto sync to happen. But I doubt that is possible. May be you can check in Mongoose. – RajaM Apr 16 '14 at 09:06