I have started with Payload recently using only a local MongoDB Docker Image, and not the Payload Docker Image.
I defined a Collection a "Project", and I noticed that when I updated my
collections/Project.ts
, the schema remained the same, as such :
// ...
{
label: "Nom du projet",
name: "title",
type: "text",
required: true
},
{
label: "Slug",
name: "slug",
type: "text",
required: true,
unique: true
},
{
label: "Année",
name: "year", // updated here due to redundancy
type: "text",
required: true
},
{
label: "Type de projet",
name: "type", // updated here due to redundancy
type: "select",
options: [
{
label: "Site web",
value: "Site web"
},
{
label: "API",
value: "API"
}
],
hasMany: false,
required: true
},
// ...
// ...
"docs": [
{
"id": "64ea5d9b704bc67c90134a44",
"title": "Portfolio 2023",
"slug": "portfolio-2023",
"project_year": "2023", // updated to "year" but stayed "project_year"
"project_type": "Site web", // update "type" but stayed "project_type"
"status": "active",
// ...
I rebuilt the MongoDB docker Image, restarted the local NodeJS server. I don't know what else I should do.
## Edit
After more checking, it only appears to do so on existing Collection Elements. It would mean that one would need to recreate a new Collection Element so the changes are visible Front-End side.
Is it an intended behavior?
Is it an intended behavior?
I think so...mongodb
basicallyworks via freeflow objects, so if you add content for key project_year it will still exist in the database unless manually removed, if you go edit those items you'll see both year and type undefined/set to default and if you save the collections again you'll also get
year
and
type
in your API response
the way to fix this is typically db migrations, this is something coming in 2.0 in payload core to help with these sorts of things
use something like mongo compass and connect to your database and you can explore the data there and see for yourself, you'll gain a better understanding of mongo this way as well
Oh alright thanks. I guess then it's solved !
I'll keep my property that way and wait for the 2.0 for migrations just in case
you can just go into the db and remove the old values!
Yes but what I actually mean is :
"
I am looking forward the update for any future change in my schema, if ever happens again"
Star
Discord
online
Get dedicated engineering support directly from the Payload team.