Troubleshooting MongoDB Change Streams Connection

Last updated on Oct 21, 2022
On This Page

If you are unable to connect to MongoDB using change streams, please verify the checklist below. You must use your auth DB to run the following commands. Additionally, you must have a root role in auth DB.

Use the following command to log in to you mongo shell. Ensure that you substitute the variables in ‘<>’ (angle brackets) with the actual values.

mongo <host.com>:<port>/<database> -u <username> -p --authenticationDatabase <auth_db>

Run the following command to switch to auth DB:

```shell
use <auth db>
```
  • Change Streams is supported only in MongoDB version 4.0 and above.
    Run the following command in the mongo shell:

     db.version()
    

    The expected output (This may vary if you have a higher version):

     4.0.0
    
  • Check if featureCompatibilityVersion is set to 4.0 or above.
    Run the following command in Mongo shell.

    db.adminCommand({getParameter: "*"}).featureCompatibilityVersion.version
    

    The expected output (This may vary if you have a higher version):

    4.0
    

    If the output is less than 4.0, run the following command to set it to 4.0

    db.adminCommand({setFeatureCompatibilityVersion: "4.0"})
    
  • Verify that the user has read role on both local DB and the DB intended to read. Run the following command in Mongo shell.

    db.getUser("<Hevo user>").roles
    

    The expected output:

    [{  
       "role" : "read",  
       "db" : "local"  
     }, {  
       "role" : "read",  
       "db" : "<db to replicate>"  
    }]
    
  • Change Streams is only supported in the wiredTiger storage engine. Run the following command in Mongo shell.

    db.serverStatus().storageEngine.name
    

    The expected output:

    wiredTiger
    
  • Change Streams is supported only when majority read concern is enabled. Run the following command. If there is no output or the output is true, it means that the majority read concern option is enabled.

    print(db._adminCommand( {getCmdLineOpts: 1}).parsed.replication.enableMajorityReadConcern)
    

    The expected output:

    [unknown type]
    

    or

    true
    

Revision History

Refer to the following table for the list of key updates made to this page:

Date Release Description of Change
Sep-05-2022 NA Brought this page under its respective Source documentation folder.
Oct-04-2021 1.73 New document.

Tell us what went wrong