Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Update shopping cart object inside Meteor user profile

I'm trying to delete from shopping cart, and change quantity information in user profile: here is the structure:

    {
      "_id": "3YmDfDWMAaoeQHPAJ",
      "profile": {
        "name": "Armin",
        "wish": [
          "FMXRAn3TEXCn6skSX",
          "avRwogpGvJsKLLKfK",
          "PJbRh68pwJrtnKe5c",
          "mt2yqLecyTA2Ejd4n"
        ],
        "cart": {
          "mt2yqLecyTA2Ejd4n": "1",
          "xqwfyqasfcyTA2ajd": "3",
          "xL438DBQrNJTJbPmH": "5"
        }
      },
      "username": "armin"
    }

I tried the following but it will delete the whole cart

    let item = $(event.target).data('id');
    Meteor.users.update(Meteor.userId(),{$unset: {"profile.cart": item}});

My goal is to be able to update the value 1,3,5 . and also be able to delete a whole property from cart.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To update an attribute's value in the cart, use $set operator like in the following query:

Meteor.users.update(
    Meteor.userId(),
    {$set: {"profile.cart.xL438DBQrNJTJbPmH": "10"}}
);

To delete an attribute in the cart:

Meteor.users.update(
    Meteor.userId(), 
    {$unset: {"profile.cart.xL438DBQrNJTJbPmH": ""}}
);

The specified value in the $unset expression (i.e. "") does not impact the operation.

In the case when you have to construct the attribute's name dynamically, you can use an additional variable:

var condition = {}; 
condition["profile.cart." + dynamicPart] = "";
Meteor.users.update(
    Meteor.userId(), 
    {$unset: condition}
);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda