Home > Software engineering >  Cannot update documents in MongoDB: "BSON field 'writeConcern.w' is the wrong type &#
Cannot update documents in MongoDB: "BSON field 'writeConcern.w' is the wrong type &#

Time:03-19

I am setting up a new new node/typescript server to connect and work with our existing MongoDB database. We keep getting this mongoose error when trying to update documents in the database:

BSON field 'writeConcern.w' is the wrong type 'array', expected types '[string, int, decimal, double, long']

Code is very simple:

const userSchema = new Schema({
  name: String, 
  email: String, 
  password: String
});

const Users = model('User', userSchema);

....

await Users.updateOne({_id: "hard-coded-id"}, {$set: {name: "Test"}}); 

I suspect a mismatch between driver versions or similar? But I've tried synchronizing mongoose versions and setup options with our other node servers.

CodePudding user response:

I Found the issue:

There was a comma in the end of my mongoDB connection uri. Apparently it made the query params in the URI invalid. Like here:

MONGODB_URI=mongodb srv://...?retryWrites=true&w=majority,
  • Related