aggregation framework - Matching on compound _id fields in MongoDB aggregate -


i'm mongodb novice please forgive me if question has obvious answer...

context:

i've followed example in mongodb docs implement hierarchical aggregation using map-reduce. example uses "compound" _id field map-reduce key producing aggregate documents this...

{    _id: { u: "rick", d: isodate("2010-10-10t14:00:00z") },    value: {        ts: isodate('2010-10-10t15:01:00z'),        total: 254,        count: 10,        mean: 25.4 } } 

this , good. particular use case requires values several similar keys emitted each map step. example...

{    _id: { u: "rick", d: isodate("2010-10-10t14:00:00z"), hobby: "wizardry" },    value: {        ts: isodate('2010-10-10t15:01:00z'),        total: 254,        count: 10,        mean: 25.4 } }  {    _id: { u: "rick", d: isodate("2010-10-10t14:00:00z"), gender: "male" },    value: {        ts: isodate('2010-10-10t15:01:00z'),        total: 254,        count: 10,        mean: 25.4 } } 

(the values same, _id keys different.)

this , good.

question:

now i'd aggregate on hierarchical collections (views), contain documents having several different compound _id fields, on documents $matching _id fields. example, i'd aggregate on documents possessing {u: string, d: date, hobby: string} type _id or documents _id of type {u: string, d: date}.

i'm aware can use $exists operator restrict _id fields should , shouldn't permitted, don't want have create separate aggregation each _id (potentially many).

is there simple way of programmatically restricting $matching documents containing (or not containing) particular fields in aggregate?

i think best way address issues storing data differently. "_id" sort of has arbitrary values key , should avoid. store documents as:

{     _id: { u: "rick", d: isodate("2010-10-10t14:00:00z"), type: hobby, value: "wizardry" } } {     _id: { u: "rick", d: isodate("2010-10-10t14:00:00z"), type: gender, value: "male" }, } 

and match because simple without having create different match each type.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -