Skip to content

$elemMatch (projection ) does not work with a new mongodb 2.2 #1085

@skotchio

Description

@skotchio

In a new version on MongoDB we can use an $elemMatch projection operator to limit the response of a query to a single matching element of an array. http://docs.mongodb.org/manual/reference/projection/elemMatch/

But it seems doesn't work yet in mongoose 3 here is the example:

{
     _id: ObjectId(5), 
     items: [1,2,3,45,4,67,9,4]
}

  Folder.findOne({_id: Object(5)}, {items: {$elemMatch: {$in: [1,67,9]}}})
    .exec(function (err, doc) { 
   });

I'm expected to get the follows doc:

  {
     _id: ObjectId(5), 
     items: [1,67,9]
 }

But unfortunately what I'm getting is document with all items:

  {
     _id: ObjectId(5), 
     items: [1,2,3,45,4,67,9,4]
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions