Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9030

Aggregation using $match and $project

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.3
    • Component/s: None
    • Labels:
      None

      I have the following following collection:

      > db.ysTest.aggregate([{$project:{_id:1,unitStatus:1}}]);
      {
      	"result" : [
      		{
      			"_id" : ObjectId("514309f3e18aa7d14100217a"),
      			"unitStatus" : "es_pws"
      		},
      		{
      			"_id" : ObjectId("514309f3e18aa7d141002816"),
      			"unitStatus" : "es_run"
      		},
      		{
      			"_id" : ObjectId("514309f0e18aa7d14100021e")
      		}
      	],
      	"ok" : 1
      }
      

      I try to run an aggregate to match a particular unitStatus, and project every record basically with just the _id and unitStatus (not other fields).
      note: I'm using aggregate because this is part of a more complicated aggregate... (i know this can be done with a find)

      I expected to have only 1 document as a result but i get everything. Am i doing something wrong ? or is this a bug?

      > db.ysTest.aggregate([{
      ... $match: {
      ...   unitStatus: {$exists: true, $nin: ["es_pws", "es_stl"]}
      ... },
      ... $project: {_id: 1,unitStatus:1},
      ... }]);
      {
      	"result" : [
      		{
      			"_id" : ObjectId("514309f3e18aa7d14100217a"),
      			"unitStatus" : "es_pws"
      		},
      		{
      			"_id" : ObjectId("514309f3e18aa7d141002816"),
      			"unitStatus" : "es_run"
      		},
      		{
      			"_id" : ObjectId("514309f0e18aa7d14100021e")
      		}
      	],
      	"ok" : 1
      }
      

            Assignee:
            michael.grundy Michael Grundy
            Reporter:
            kurteknikk Kurt Agius
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: