Update Simple Smart Field Nested Objected

Hello,
I think I have a pretty simple issue but I don’t understand :frowning:
I checked this doc Display/edit a nested document - Woodshop

Whenever I update the email, the first name is deleted and opposite for first name / email.

    {
      field: "email",
      type: "String",
      get: (lead) => {
        return lead.person.email || "";
      },
      set: async (lead, value) => {
        console.log(lead, "=====");
        if (!lead.person) {
          lead.person = {};
        }
        lead.person.email = value;
      },
    },
    {
      field: "jobTitle",
      type: "String",
      get: (lead) => {
        return lead.person.job_title || "";
      },
    },
    {
      field: "firstName",
      type: "String",
      get: (lead) => {
        return lead.person.firstname || "";
      },
      set: async (lead, value) => {
        console.log(lead, "====");
        if (!lead.person) {
          lead.person = {};
        }
        lead.person.firstname = value;
      },
    },

Hello @Robin_Herzog,

Thanks for your feedback. Can you please share with us the other info that are requested in the template for new questions in this forum? It’ll help us a lot identify the origin of the issue.

This is a template you can use to report issues. You can also drag images, videos and include Preformatted text

Expected behavior

Please describe here the behavior you are expecting.

Actual behavior

What is the current behavior?

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version:
  • Express Version:
  • Sequelize Version:
  • Database Dialect:
  • Database Version:
  • Project Name:

Expected behavior

Update a custom smart fields without deleting other current value in the same object

Actual behavior

When I update a smart field, all other smart fields are set as empty

Failure Logs

  {
      field: "email",
      type: "String",
      get: (lead) => {
        return lead.person.email || "";
      },
      set: async (lead, value) => {
        console.log(lead, "=====");
        if (!lead.person) {
          lead.person = {};
        }
        lead.person.email = value;
      },
    },
    {
      field: "jobTitle",
      type: "String",
      get: (lead) => {
        return lead.person.job_title || "";
      },
    },
    {
      field: "firstName",
      type: "String",
      get: (lead) => {
        return lead.person.firstname || "";
      },
      set: async (lead, value) => {
        console.log(lead, "====");
        if (!lead.person) {
          lead.person = {};
        }
        lead.person.firstname = value;
      },
    },

Context

Please provide any relevant information about your setup.

  • Package Version: last
  • Express Version: last
  • Database Dialect: Mongo
  • Database Version: last
  • Project Name: revenue-accelerator

Why in (lead) it only contain the value of the current updated field and not the full payload ?

{
  email: 'sarah.harrison@convenzis.co.ukkk',
  _id: '6128e4f9df637a18f8d21957'
}

When I search for the current value, it update nothing

     // const customerBeforeUpdate = await leads.findById(lead._id);
        // lead = customerBeforeUpdate;
        lead.person.email = value;
        return lead;
``

Hi @Robin_Herzog,

Can you please share the lead models?

Regards

module.exports = (mongoose, Mongoose) => {
  const schema = Mongoose.Schema(
    {
      _id: { type: Mongoose.Schema.Types.ObjectId },
      organizerID: { type: Mongoose.Schema.Types.ObjectId, ref: "organizers" },
      eventID: { type: Mongoose.Schema.Types.ObjectId, ref: "events" },
      source: {
        scraper_name: String,
        origin: String,
        sourcePage: String,
      },
      batch_id: { type: Mongoose.Schema.Types.ObjectId, ref: "batches" },
      person: {
        email: String,
        firstname: String,
        lastname: String,
        linkedin: String,
        job_title: String,
        phone: String,
      },
      company: {
        name: String,
        domain: String,
      },
    },
    {
      timestamps: false,
    }
  );
  return mongoose.model("leads", schema, "leads");
};

// module.exports = mongoose.model("leads", schema, "leads");

Hi @Robin_Herzog,

The problem is reproduced on our side: we have to fix the issue, brother’s properties should not be deleted when there is a smart field update a nested field.

This ticket traces the issue.

Regards

1 Like