Querying by _id with $pull and $in

35 views
Skip to first unread message

anton kropp

unread,
Mar 25, 2013, 10:42:47 AM3/25/13
to mongoo...@googlegroups.com
Hi, I'm new to mongo so hopefully this isn't a foolish question. I have a document schema set up like 

tracks:
    dataPoints = [ DataPoints]

So dataPoints are an embedded document list inside of a track.

I am trying to remove data points from the list based on Id.  In the mongo shell I can do this:

db.tracks.update({}, {$pull : {'dataPoints' : { '_id' : { $in : [ ObjectId("514f90664a12b4441800007e") ]  }}}}, false, true);

And this works fine.  

Using mongoose however, if I have a mongoose object that has an ObjectId property I can't just do

schema.Track.update({}, {
            $pull: {
                dataPoints: {
                    _id: {
                        $in: [points[0]._id]
                    }
                }
            }
        }, {
            multi: true,
            upsert: false
        }, function (err) {
            return callback(err);
        });

I get no error, but nothing happens. I've validated that points[0]._id is a mongoose ObjectId type. Any ideas whats going on here? I don't get any errors just nothing is committed.

anton kropp

unread,
Mar 25, 2013, 10:48:44 AM3/25/13
to mongoo...@googlegroups.com
I should mention the same query works fine for any other non _id field. If i change the "in" to be on some other piece of data (like a string) then it works fine
Reply all
Reply to author
Forward
0 new messages