MongoDB and Mongoose - Create and Save a Record of a Model, user is not allowed to do action [insert] on [test.people]


I have done the exercise exactly how I’m asked to but I keep getting this error, I already searched for it but no one seems to have posted about it.

MongoError: user is not allowed to do action [insert] on [test.people]
    at MessageStream.messageHandler (/home/user/Desktop/freeCodeCamp/Mongoose/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/connection.js:299:20)
    at MessageStream.emit (node:events:390:28)
    at processIncomingData (/home/user/Desktop/freeCodeCamp/Mongoose/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/home/user/Desktop/freeCodeCamp/Mongoose/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (node:internal/streams/writable:390:12)
    at _write (node:internal/streams/writable:331:10)
    at MessageStream.Writable.write (node:internal/streams/writable:335:10)
    at TLSSocket.ondata (node:internal/streams/readable:777:22)
    at TLSSocket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:234:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23) {
  ok: 0,
  code: 8000,
  codeName: 'AtlasError'

My code:


/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("Connection successful!"))
.catch((err) => console.log("Connection SUCKS!", err.message));

//Create Schema
const { Schema } = mongoose;

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

//Create Model
let Person = mongoose.model('Person', personSchema);

const createAndSavePerson = (done) => {
  let john = new Person({ name: 'John', age: 55, favoriteFoods: ['string1', 'string2'] });, data) {
    if (err) return console.error(err);
    done(null, data);

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0

MongoDB and Mongoose - Create and Save a Record of a Model

Any solutions?

Thank you!

1 Like

I was sure I did, is it possible to edit or do I need to restart? Project role is “Project Owner”

That solved it, thank you very much!

I’m sure I followed every step but maybe I missed that one.

1 Like

This saved me a lot of time/trouble. Thanks!!!

I was also getting the same problem
Thanks for the solution It helped me a lot :slight_smile:

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