MongoDB create and save timeout

Tell us what’s happening:
My solutions to this are timing out.

I’ve checked the previous queries on this issue. I’m already using replit and I’ve also tried making the URI connection adjustments suggested in a previous answer (I’m limited to only two links, sorry).

The following error message is in the console, but I’m not clear on what it means.

MongoWriteConcernError: No write concern mode named 'majority'' found in replica set configuration
    at MessageStream.messageHandler (/home/runner/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/connection.js:463:30)
    at MessageStream.emit (events.js:314:20)
    at processIncomingData (/home/runner/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
    at MessageStream._write (/home/runner/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at MessageStream.Writable.write (_stream_writable.js:318:11)
    at TLSSocket.ondata (_stream_readable.js:718:22)
    at TLSSocket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12) {
  code: 79,
  codeName: 'UnknownReplWriteConcern',
  errInfo: {
    writeConcern: { w: "majority'", wtimeout: 0, provenance: 'clientSupplied' }
  result: {
    n: 1,
    opTime: { ts: new Timestamp({ t: 1630245700, i: 1 }), t: 51 },
    electionId: new ObjectId("7fffffff0000000000000033"),
    ok: 1,
    writeConcernError: {
      code: 79,
      codeName: 'UnknownReplWriteConcern',
      errmsg: "No write concern mode named 'majority'' found in replica set configuration",
      errInfo: [Object]
    '$clusterTime': {
      clusterTime: new Timestamp({ t: 1630245700, i: 1 }),
      signature: [Object]
    operationTime: new Timestamp({ t: 1630245700, i: 1 })

My code is:

const mongoose = require('mongoose')


const { Schema } = mongoose

const personSchema = new Schema({
  name : {type: String, required: true},
  age : Number,
  favoriteFoods : [String]

const Person = mongoose.model("Person", personSchema)

var createAndSavePerson = async function(done) {
  var person = new Person({
    name: 'Jane Fonda', 
    age: 84, 
    favoriteFoods: ['vodka', 'air']
  });, data) {
    if (err) return console.error(err);
    done(null, data)

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Create and Save a Record of a Model

Link to the challenge:


The problem is that you’re not calling done if there’s an error:

if (err) {
  return done(err);

And async is not necessary in this case:

var createAndSavePerson = async function

For the actual error, can you show me the mongo URI? (Remove the user name and password from the URI).

Hi, thanks for your help, the test is now accepting my code. I had to delete a query string from the end of my mongo URI.


Yes, it finally work after I’ve deleted the end part of querry string

<?retryWrites=true&w=majority> in my secret file MONGO_URI. Thank you ! :sweat_smile: Here is the .env file should be in json format (I'm using Replit): 'MONGO_URI':'mongodb+srv://'

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