NodeBB MongoDB Replica Set Read Preference

  • I am using NodeBB 1.5.3. I have configured NodeBB to use MongoDB Replica set as follows:

    "mongo": {
      "host": ",,",
      "port": "27017,27017,27017",
      "username": "nodebb",
      "password": "passw0rd",
      "database": "nodebb?replicaSet=rs0&slaveOk=true"

    But its still sending all traffic to primary MongoDB server and not using slaves to read data. I see a lot of find queries in primary MongoDB server's log file.

    2018-10-03T12:32:52.047+0000 I COMMAND  [conn6070] command nodebb.objects command: find { find: "objects", filter: { _key: /user:/i, username: "admin" }, limit: 1, singleBatch: true, batchSize: 1 } planSummary: IXSCAN { _key: 1, value: -1 } keysExamined:110998 docsExamined:707 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:867 nreturned:1 reslen:1121 locks:{ Global: { acquireCount: { r: 1736 } }, Database: { acquireCount: { r: 868 } }, Collection: { acquireCount: { r: 868 } } } protocol:op_query 104ms

    I have also tried using readPreference=secondary instead of slaveOk=true but in this case NodeBB doesn't startup. It hangs. I have to kill the process and try again and it still does the same thing over.

    Can someone help me figure this out? How do I use secondary servers as read only with NodeBB?

  • @NIXKnight I'd be interested in the solution to this as well.

  • NodeBB Admin

    Your config looks fine, not sure why it is only reading from a single one.

    { find: "objects", filter: { _key: /user:/i, username: "admin" }

    This doesn't look like a query we do in core nodebb, do you have some plugins that run custom queries? This doesn't use the indexes properly should probably be

    { find: "objects", filter: { _key: /^user:\d+$/i, username: "admin" }

Suggested Topics

| | | |