Daniel Weiß
Daniel Weiß

Reputation: 119

mongodb: remove an object from array

i would like to remove a object from an array that matches "market"

my document:

{
    _id: "brTuuCYhdcQSsr2xL",
    marketConfig: [
        { market: "de", value: 123 }
        { market: "cn", value: 456 }
    ]
}

my javascript code:

Database.update(
    { _id: "brTuuCYhdcQSsr2xL" },
    { $pull: { marketConfig: { market: "de" } } },
);

after i fire this js code, the document looks like still the same

i am confused... i got no errors messages with this...

Upvotes: 0

Views: 71

Answers (1)

Harisudhan. A
Harisudhan. A

Reputation: 672

Try this,

Database.update(
   { _id: "brTuuCYhdcQSsr2xL" },
   { $pull: { marketConfig: { market: "de" } } },
  false,
  true 
);

you have to commit your query by passing the boolean parameters.

Upvotes: 1

Related Questions