NodeBB MongoDB Replica Set Read Preference

Technical Support
  • 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.

  • 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

  • 0 Votes
    1 Posts


    I have a test NodeBB forum, running on Digital Ocean. In this instance, I am changing certain settings through the Admin panel:

    Installing and activating plugins Modifying settings such as list of categories

    I am planning now to install a new forum instance, production one, also on Digital Ocean. What is the best way to copy forum settings from test to production (just plugins and settings, without users and posts)? Note that I would like to make this "settings update" on a regular basis.

    Thank you.

  • 0 Votes
    3 Posts

    I was able to install it by following the instructions from here:
    I already have node.js installed on my computer. I did not install redis or nginx.
    I have a mac, so on Terminal, after I created a directory called "nodebb", I skipped the first few lines of the instructions, and just pointed to the directory I created, by using the "cd" command. I then created another directory called NodeBB inside the nodebb directory. You may skip creating two directories and just create a directory called "NodeBB". I pointed to this directory by using the cd command.
    Then this line
    "git clone -b v1.15.x ."
    was the key for me.
    After I typed that, nodebb was cloned to the directory.
    Then I ran "./nodebb setup".
    I used mongo for the database.
    When prompted, I pasted the connection string that I got from mongodb's site. I substituted "nodebb" for the database part in the string. (I set up mongodb (Cloud Atlas) beforehand). The instructions that come up on Terminal will tell you to call your database "nodebb".
    After that step, the program ran automatically and installed the files. It asked me to put in the username and password for mongodb and it also asked me to choose a name for admin and password. You might have to wait a while as it pauses for a long time after "Confirm Password". I thought there was some problem and was tempted to abort the operation, as it was taking a long time, but it did come up with further instructions after a while.
    I typed "./nodebb start" when the setup finished and then went to "localhost:4567", and this time, I was able to see a normal board, and could log in as admin.
    I write this follow-up in case another mac user has trouble installing nodebb. In the end, setup was pretty straightforward and did not involve a lot of steps. My OS is High Sierra.
    The instructions, including the ones for Linux, at the official nodebb site did not work for me.

  • 0 Votes
    6 Posts

    @phenomlab That worked 👍

  • 0 Votes
    3 Posts

    Ok. Looks like it was because of a incompatible plugin. The plugin in my case was nodebb-plugin-reddcoin . Its fixed now. Though i can't use the reddcoin plugin. Was a nice plugin 👍

  • 0 Votes
    3 Posts
    1k Views said:

    Please look here.

    thank you, i understand the procedure for null topic but not sure for null users