MongoServerError but not in compass

Hi, My mongosh within Compass is working fine - example from compass :
db.movies.aggregate([
{ ‘$match’: { ‘imdb.rating’: { ‘$gte’: 7 } } }
]).itcount() => 15204

The 2nd lab requires a load command outside of the compass Mongosh
I appear to be on correctly because I can list the collections in the aggregations db

However commands like above work on compass Mongosh but not Mongosh ( proper?) as it gives:
MongoServerError: not primary and secondaryOk=false - consider using db.getMongo().setReadPref() or readPreference in the connection string

I did not find any MongServerError in the previous forum entries

I noticed I used the connection string from compass:

Please enter a MongoDB connection string (Default: mongodb://localhost/): mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true
Please enter a MongoDB connection string (Default: mongodb://localhost/): mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=true
Current Mongosh Log ID: 62ad5e454c9d0419fc869697
Connecting to: mongodb://@cluster0-shard-00-00-jxeqq.mongodb.net:27017/?authSource=admin&readPreference=primary&appname=MongoDB+Compass&ssl=true&directConnection=true
Using MongoDB: 4.2.20
Using Mongosh: 1.5.0

And I see readPreference in tne connection string
Any suggestions ( will click on the checked box for your helpful reply ). Thanks !

your uri is not correct. you are specifying a single host and are not specifying the replica set. please refer to the first chapter for the correct uri.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.