Search code examples
javascriptnode.jsmongodbmlab

MongoError: Majority read concern requested, but it is not supported by the storage engine


I am using mlab free tier, and I'm trying to use change streams in my app. Here's my code:

const config = require('../globals/config');
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect(config.db, {useNewUrlParser: true}, function (err, client) {
    const db = client.db('web-project-studio-db');
    // Connect using MongoClient
    var filter = [{$match: {'_id': user._id}}];

    db.collection('accounts').watch(filter).on('change', data => {
        console.log(data);
    });
});

This says:

MongoError: Majority read concern requested, but it is not supported by the storage engine.

Is there something I should enable in mlab settings, or did I just mess something up?


Solution

  • To use watch you need to use replica set which is not part of mLab free plan.