Extend an array inside an array

Like Find a document with an array that contains a specific value , but I'm trying to pull it out.

db.getCollection('users').find({'favorites':{$elemMatch:{0:5719}}}, {"favorites.$": 1})

returns this:

{
    "_id" : "FfEj5chmviLdqWh52",
    "favorites" : [ 
        [ 
            5719, 
            "2016-03-21T17:46:01.441Z", 
            "a"
        ]
    ]
}

even after that returned 1:

Meteor.users.update(this.userId, {$pull: {'favorites':{$elemMatch:{0:movieid}}}})
+4
source share
2 answers

This is the first code I found that really works:

Meteor.users.update(Meteor.userId(), {$pull: {favorites: {$in: [i]}}})

Apparently $inperforms a partial match. This seems more secure than the working code for this answer :

Meteor.users.update(
    { "_id": this.userId },
    { "$pull": { "favorites": { "$elemMatch": { "$eq": i } } } }
)
0
source

, $pull "favorites". , , - " " .

, nth, $pull :

Meteor.users.update(
  { "favorites": { "$elemMatch": { "$elemMatch": { "$eq": 5719 }  } } },
  { "$pull": { "favorites.$": 5719 } }
)

"double" $elemMatch $eq , { 0: 5719 }, "" . , , " ", .

, "", positional $, "" .

, , :

  { "$pull": { "favorites.0": 5719 } }

" ", , .

:

{
        "_id" : "FfEj5chmviLdqWh52",
        "favorites" : [
                [
                        "2016-03-21T17:46:01.441Z",
                        "a"
                ]
        ]
}

$pull , $eleMatch :

Meteor.users.update(
    { "_id": this.userId },
    { "$pull": { "favorites": { "$elemMatch": { "$eq": 5719 } } } }
)

:

Meteor.users.update(
    { "_id": this.userId },
    { "$pull": { "favorites": { "$elemMatch": { "0": 5719 } } } }
)

, :

    { "_id": this.userId },

, "", "" _id . MiniMongo , , _id .

"" $elemMatch, $pull .

:

{
        "_id" : "FfEj5chmviLdqWh52",
        "favorites" : []
}
+2

All Articles