Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1031

How to use aggregation framework for grouping on column which doesn't exist in some of the documents

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      Hello,
      We have schema in one of our collection called 'assets' as following

      {
      "_id" : "002992f0b34241a38f6c2336b52c480b",
      "storage" : {
      "size" : 0,
      "sha256" : null,
      "account_id" : "bab7a257b8db102d513eee5c279522aa",
      "updated" : NumberLong("1439473126075068"),
      "revision" :

      { "_id" : "da3b4547944f48fda7ea542cbc5d0e43", "source" : "importSource.fileSize" }

      },
      "created" : NumberLong("1439473126075068"),
      "subtype" : "video"
      "updated" : NumberLong("1439473126075068"),
      "catalog_id" : "35575220144c48e98f158cac91b5e5f9",
      "payload" :

      { "captureDate" : "2015-08-13T19:08:45Z", ..... }

      ,
      ....
      }

      We want to group the documents in this collection by subtype and planning to use query something like:

      db.assets.aggregate({ $match: { catalog_id: "35575220144c48e98f158cac91b5e5f9", deleted: {$exists: false}}} , { $group:

      { _id: "$subtype"}

      });

      However, the "subtype" field may not be present in all the documents and we want to group such documents under one category (images). How can we achieve this using aggregation framework ?

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            nikhijai nikhil jain
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: