Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 271

'No write concern mode named 'majority`' found in replica set configuration' error

$
0
0

I'm trying to insert an object into mongodb via a POST request. The object that I send gets inserted in the db successfully, however I get the error mentioned above.

The package I'm using for mongo db:

https://github.com/mongodb/mongo-go-driver

Connection string

mongodb+srv://user:password@bookcluster.pxcqs.mongodb.net/DBname?retryWrites=true&w=majority`

The way I set up the database connection:

var DbConn *mongo.Client //*sql.DB //*mongo.Clientfunc SetupDB(conn_str string) {    var err error    DbConn, err = mongo.NewClient(options.Client().ApplyURI(conn_str))    if err != nil {        log.Fatal(err)    }    ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)    err = DbConn.Connect(ctx)    if err != nil {        log.Fatal(err)    }}

My object:

package bookimport "go.mongodb.org/mongo-driver/bson/primitive"type Book struct {    Id        primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`    Title     string             `json:"title" bson:"title"`    Author    string             `json:"author" bson:"author"`    Year      int                `json:"year" bson:"year"`    ShortDesc string             `json:"shortDesc" bson:"shortDesc"`    Genre     string             `json:"genre" bson:"genre"`}

Here's how I send the request inside insertBook() (where b is of type Book):

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)    defer cancel()    result, err := database.DbConn.Database(dbName).Collection(collectionName).InsertOne(ctx, b)

Full error text:

multiple write errors: [{write errors: []},{(UnknownReplWriteConcern) No write concern mode named 'majority`'found in replica set configuration}]

My request in Postman

I'm not sure if I'm missing some sort of a configuration setting somewhere - I just started with mongoDBI tried to follow the example set in these tutorials: 3, 4 and they don't seem to mention anything about the 'write concern' and 'majority'.Also tried looking into the documentation and googling the error but didn't find anything helpful.


Viewing all articles
Browse latest Browse all 271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>