Search code examples
node.jsmongodbsails.jswaterlinesails-mongo

How to read from one database and write to other database in Sails.js


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


Solution

  • 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'
    },