Update a field that contains an empty value

Feature(s) impacted

Updating a field in a “child” collection

Failure Logs

None

Context

  • Agent technology: NodeJS (Express)
  • Agent (forest package) name & version: forest-express-mongoose (9.3.17)
  • Database type: MongoDB, Mongoose

Message

Hello!

I’m trying to update a field that contains an empty value. (example : john@doe.comnull | "")

Here is the data structure:

const StoreSchema = new mongoose.Schema(
  {
    name: { type: String, required: true },
    websites: { type: [WebsiteSchema], required: false, default: [] },
  }
)

export const WebsiteSchema = new mongoose.Schema(
  {
    name: { type: String, required: true },
    url: { type: String, required: true },
    color: { type: String, required: false },
    email: { type: String, required: false },
  },
  { _id: false }
)

When I change the “email” field of one of my websites to an empty value, forest tells me “websites successfully updated.”, but as soon as I refresh the page, the value is back to what it was before…

I created a middleware in my API to understand the body that is sent when I set the “email” field to empty:

{
  data: {
    attributes: {
      name: 'test_website',
      url: 'https://my_url.com',
      color: '#FFF'
    }
  }
}

Concretely, as I passed email to "", it is not sent, and therefore not modified.

From what I remember, we didn’t have this problem before. Has anything changed? And if not, what would the workaround be?

Thank you very much!

Hello @CMonjo

Thanks for reporting your issue and sorry for inconvenience. I am able to reproduce the bug locally, we will work on a fix and come back to you when it will be released.

Nicolas

2 Likes

This is great!

Thanks a lot
Camille

Hello,

I’d like to relaunch the conversation to see if a solution has been found.

Thank you very much,
Camille Monjo

Hello @CMonjo

The fix is still in review, I will come back to you once it’s released.

Nicolas

Hello @CMonjo

The fix has been released.

Sorry for the inconvenience.

Nicolas

Hi @nbouliol

Thank you so much for your responsiveness!

And thanks to the entire Forest team for making such a cool product!!

2 Likes