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”,