Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update item delete all translations #26

Open
xAgustin93 opened this issue Sep 6, 2019 · 1 comment
Open

Update item delete all translations #26

xAgustin93 opened this issue Sep 6, 2019 · 1 comment

Comments

@xAgustin93
Copy link

When you update any item all the translations of all languages are deleted and the new one is left, I leave an example.

DB Data Item

{
    "_id" : ObjectId("5d7231abc433597019287930"),
    "name" : {
        "es" : "Aspiracion",
        "en" : "Aspiration"
    },
    "slug" : {
        "es" : "Aspiracion",
        "en" : "Aspiration"
    },
    "description" : {
        "es" : "Toda la aspiracion.",
        "en" : "Aspiration"
    },
    "children" : [],
    "featuredProduct" : null,
    "__v" : 0
}

Function Update collection by ID.

function updateCategory(req, res) {
  const { lang } = req.headers;
  const params = req.body;
  params.name = { [lang]: params.name };
  params.slug = { [lang]: params.slug };
  params.description = { [lang]: params.description };
  const { _id } = params;

  Category.findByIdAndUpdate({ _id }, params, (err, categoryUpdateData) => {
    if (err) {
      res.status(500).send({ message: "Error del servidor." });
    } else {
      if (!categoryUpdateData) {
        res.status(404).send({
          message: "No se ha encontrado la category que se quiere modificar"
        });
      } else {
        res.status(200).send({ category: categoryUpdateData });
      }
    }
  });
}

Result item DB, and delete all translations.

{
    "_id" : ObjectId("5d7231abc433597019287930"),
    "name" : {
        "es" : "Aspiration"
    },
    "slug" : {
        "es" : "aspiration"
    },
    "description" : {
        "es" : "All aspiration."
    },
    "children" : [],
    "featuredProduct" : null,
    "__v" : 0
}

Petition Http for Postman.

Header: https://ibb.co/7QkCwct
Body: https://ibb.co/7QkCwct

@ArthurJahn
Copy link

The findByIdAndUpdate updates the entire document. Instead of passing the object directly, use the $set option. This is not a plugin related issue. See the updating section of the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants