We’ve been testing ForestAdmin with a MongoDB database since last week. We have some problems with data that isn’t in the mongoose model of the database.
If I add a new property to an object of my database, I should add it manually in the models of my forest admin backend.
It is not very practical and if I don’t add this property to the model, I can’t see it in ForestAdmin. Moreover, when I update my data with the ForestAdmin panel, the property even gets removed from the database (which can delete some data from the database !).
Example: if I add a property
testProp in the profile object of my user, without putting it in the model file
users.js, it gets deleted from the database when I update the profile object in the ForestAdmin panel.
I tried to set strict mode to false in my database schema, but the data of my smart fields get added in my database, at the root of the document and with the wrong key (see the ‘Viewer token duration (hours)’ property added by Forest) :
If the database model isn’t up-to-date, why does ForestAdmin delete the data that isn’t in the model? And without any warning?
A solution is using “strict: false” in the schema of the mongodb collection, but then why does ForestAdmin add unwanted fields (the smart field values) to my documents when I update them using the admin panel?
Currently, to update our database schema we found two solutions:
- Update it manually each time we modify the database structure, and push it into production
- Delete the old model files (existing files can’t be updated), use
forest schema:update to scan the whole database and regenerate all files, rewrite our modifications, then push it into production
Both solutions can be time-wasting for our team and we wonder if there is an easier way to do that?
- Project name: -
- Team name: -
- Environment name: all environments
- Agent type & version: forest-cli/2.6.3 with express/mongoose v8
Thank you for this valued feedback.
First of all, I’ve created a bug ticket in order to fix the data deletion inside the embedded document having properties not defined in the schema. Best regards for pointing this out. I am not able to give an ETA about this, but it should be studied in a short amount of time.
Secondly, I’ve also created a bug ticket in order to fix the problem of writing smart fields into the database when using strict mode.
Waiting for the first bug to be fixed, I am afraid you already point out the workarounds like you said to update schema rigorously.
Thanks for your quick answer.
Is-it possible to notify us when these problems are fixed ? We will wait for it.
I would like to know if it is possible to have an update on the status of these fixes ?
All my apologies for the lack of update.
The bug was returned as non-reproductible since the sub-document properties are updated one by one.
Do you have some route override on your setup?
What is your express/mongoose version? Last is 8.6.7
Hello @Sliman_Medini ,
Thanks for your answer.
I don’t override any of the default routes created by ForestAdmin.
I was using express/mongoose version 8.6.5, I’ve updated to 8.6.7, but I still have these bugs. I will illustrate them:
- For the first bug, data deletion:
- I add two properties to my mongodb document, that are not in the mongoose model used by ForestAdmin.
Mongoose model of my document:
Data in my database:
The two properties
display.otherTest are not in the model.
- I open this profile on the ForestAdmin panel:
The profile field is displayed like this, as it’s an object, and it’s editable.
You can note that the additional properties
display.otherTest are not shown (and this is not a problem for us since they are not in the database model).
- The bug happens when I edit the “profile” object: if I update
display.someDisplaySetting, the other properties (
display.otherTest) get deleted, without any warning or error message. Here is the result in the database when I do this modification:
Finally, as our database model may not be up-to-date every time (we choose MongoDB for its flexibility, without having to define a model), it may be a big issue to accidentally lose data like these.
- And then the second bug, only when I set “strict: false” in my database schema:
I have a smart field “Viewer token duration hours” linked to
If I update it, a new property is created in my database document, for each SmartField:
I hope my explanations will help you reproduce and solve these bugs. Feel free to email me if you want more details.
Thanks for your help.
I would like to know if you have any news on these bugs ?