0

I have a multi-region database (MongoDB) infrastructure with replication. I want to record data to master DB and read data from other DB (replication) in the same region with the application server. How to implement it? Thanks

MonstroDev
  • 190
  • 2
  • 12

2 Answers2

1

Instead of trying to solve the problem on the application level I would go with the MongoDB Read Preference configuration. This approach has at least two advantages:

  • your code does not change
  • the functionality relies on the optimized and tested MongoDB engine
svet
  • 11,078
  • 1
  • 15
  • 26
0

In config/connection.js:

mongodb: {
  adapter   : 'sails-mongo',
  ssl: {
    rejectUnauthorized: false
  },
  url: 'mongodb://0.0.0.1,0.0.0.2:27017/db-name?replicaSet=rs0',
  readPreference: 'secondary'
},
MonstroDev
  • 190
  • 2
  • 12