Error deleting deeply nested item using nodejs and mongodb

Feature(s) impacted

Having array within array in mongoDB and nodejs

Observed behavior

When there is a schema like this:

const AttributeValueSchema = new Mongoose.Schema({
  label: { type: String, required: true },
  order: { type: Number, required: true }
});

const AttributeFieldSchema = new Mongoose.Schema({
  label: { type: String, required: true },
  values: [AttributeValueSchema],
  order: { type: Number, required: true }
});

const programsSchema = new Mongoose.Schema({
  attributeFields: { type: [AttributeFieldSchema], default: {} },
});

Then you can created attributeFieldsValues but you can not delete them. When you try to delete them you get an error, “MongoServerError: Third argument to $slice must be positive: 0.” This is with flattenMode: ‘auto’.

Expected behavior

It should delete without issue

Context

  • Project name: Sageful Admin
  • Database type: MongoDB
  • Recent changes made on your end if any: N/A

And, if you are self-hosting your agent:

  • Agent technology: nodejs

  • Agent (forest package) name & version (from your .lock file):

  • @forestadmin/agent”: “^1.65.0”,

    "@forestadmin/datasource-mongoose": "^1.12.3",
    

Hi @DrewB :waving_hand: welcome to our community.
Thank you for the reproduce case, i confirm there is an issue here.
Can you just send me the version of mongoose you were using, to be sure I’m on the same setup as you. :folded_hands:

I am using mongoose 7.0.0

A fix has been released, can you upgrade your package to 1.12.4 :folded_hands: and try again?

1 Like

Issue is fixed! Thank you!

1 Like