Nested JSON documents from Mongoose won't save values when copy pasting

Feature(s) impacted

  • Nested documents of a mongo document in the UI
  • Mongoose schema

Observed behavior

  • Open the ‘data’ page for the mongo collection in the UI
  • Enter a new record against the collection that has nested documents in the schema
// A simple example of the backing schema
const characteristicSchema = new mongoose.Schema({
  name: { type: String },
});

const attributeSchema = new mongoose.Schema({
  name: { type: String },
  characteristics: { type: [characteristicSchema], default: [] },
});

const glossarySchema = new mongoose.Schema({
  name: {
    type: String,
    unique: true,
  },
  type: { type: String },
  attributes: { type: [attributeSchema], default: [] },
}, { collection: 'glossary' });

connection.model('glossary', glossarySchema);
  • Enter the top level properties in the input fields that are rendered

  • Enter a JSON object into the text area that is rendered for the “attributes” sub document with valid schema values

  • Click create button.

  • If you type the values in, this works.

  • If you paste the JSON values in and use the keyboard in some way (delete a character, enter a new character), this works

  • If you paste the JSON values in and just click submit, the payload sent (through networking tab) and the response back DO contain the correct number of “characteristics” objects in the payload and the response, but it clears all their values. So you have the correct number of objects in the array, but none of their properties.

This is the simple payload I have been using (typing out, pasting in, and editing the text after pasting)

[{ "name": "attr name 1", "characteristics": [{ "name": "char name 1" }]}]

Here is an example of the result in mongo when using copy paste and making no edits with the keyboard before submitting:

{
  "_id": {
    "$oid": "680f48aa3ce7ca256637d5eb"
  },
  "name": "check",
  "type": "check",
  "attributes": [
    {
      "characteristics": [],
      "_id": {
        "$oid": "680f48aa3ce7ca256637d5ec"
      }
    }
  ],
  "__v": 0
}

Expected behavior

  • If you enter the JSON by hand, the values are saved to the database and the “details” screen shows the top level properties and the sub document values.
  • If you enter the JSON by pasting it in (exactly the same values that you would typed in the step above), the behaviour is the same.

Failure Logs

  • NA

Context

  • Environment name: .Development, Production

  • Database type: Mongo

  • Recent changes: NA

  • Agent technology: nodejs

  • Agent (forest package) name & version (from your .lock file): “@forestadmin/agent”: “^1.60.1”,

Hello @jakec

Thank you for reporting this bug, we are able to reproduce it.

We will treat it and come back to you once it’s fixed.

Sorry for the inconvenience.

Nicolas

1 Like

Hi @jakec,

We’ve released a fix.
Is it working on your side now ?

1 Like

I’ve just upgraded a test environment to use the latest for each forestadmin package and can confirm that the issue has been resolved

Amazing turn around time on this one folks - thank you

1 Like