Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!