Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion MapReduce when field doesn't exist in every document

Received: by 10.101.128.12 with SMTP id f12mr7001107ann.27.1336432149703;
        Mon, 07 May 2012 16:09:09 -0700 (PDT)
X-BeenThere: mongodb-user@googlegroups.com
Received: by 10.236.176.198 with SMTP id b46ls6988002yhm.2.gmail; Mon, 07 May
 2012 16:08:58 -0700 (PDT)
Received: by 10.101.179.3 with SMTP id g3mr5261181anp.2.1336432138597;
        Mon, 07 May 2012 16:08:58 -0700 (PDT)
Received: by 10.101.179.3 with SMTP id g3mr5261179anp.2.1336432138559;
        Mon, 07 May 2012 16:08:58 -0700 (PDT)
Return-Path: <sam.mill...@gmail.com>
Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182])
        by gmr-mx.google.com with ESMTPS id t12si17917909yhh.7.2012.05.07.16.08.58
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 07 May 2012 16:08:58 -0700 (PDT)
Received-SPF: pass (google.com: domain of sam.mill...@gmail.com designates 209.85.213.182 as permitted sender) client-ip=209.85.213.182;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of sam.mill...@gmail.com designates 209.85.213.182 as permitted sender) smtp.mail=sam.mill...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-yx0-f182.google.com with SMTP id l9so7283347yen.27
        for <mongodb-user@googlegroups.com>; Mon, 07 May 2012 16:08:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=BTT5Z85n0/QELbtEREnHfvO+ZtDSD/6X1G434fUW57A=;
        b=ezFpicVo86ONlonxMkEwSJKrwIzAF4EFWLreRovEYaUZljkvlqOvjr4QiJgUM6Kuty
         3f9iqF70GiKBEl0BTBA/2DqXLAyez8O1C9XFc6IL0/B/LLMfx3GPbp+DDtvV4vyTNyWx
         2/WAXRoU2dKnW5ZXdde+s+PAKJSfJVK3m+D3exodwTZu7l+C/B4Em9b3op7V+beisZXv
         rX2o6N7+B5osxOQnfc4QkKApOP9YXrgJNjucnJnHC6uo+M5xELW+SaOYy6is3vE8l5IA
         I+VxN+r5nKW8HNZePp19JuYr9zViRuHo9XyasLqVWVXWSJM+5jDaV0rouOU08RUXc/wJ
         BehA==
MIME-Version: 1.0
Received: by 10.236.153.36 with SMTP id e24mr21356991yhk.66.1336432138409;
 Mon, 07 May 2012 16:08:58 -0700 (PDT)
Received: by 10.236.200.225 with HTTP; Mon, 7 May 2012 16:08:58 -0700 (PDT)
In-Reply-To: <ccaf774c-eed8-4afe-be46-d253d7ad5...@c30g2000vby.googlegroups.com>
References: <c79967b1-350b-4e9c-a9da-3b152c69f...@m10g2000vbb.googlegroups.com>
	<3466f353-9be5-421b-9c67-ed01a9618...@j16g2000vbl.googlegroups.com>
	<cc648484-2ae5-4681-bacf-15be87640...@v17g2000vbg.googlegroups.com>
	<CALKyTE4vbRU=7R+j+7g3NNoYrcqn9JOhPfvrgq6wyoscGmB...@mail.gmail.com>
	<a9386627-8811-4a39-ba96-c823901e1...@a3g2000vbm.googlegroups.com>
	<CALKyTE6cWpN25B3YDVms0BV+CxJ-jfXoOwthLe4cEcTWCy+...@mail.gmail.com>
	<CALKyTE5SXC_m0Wvk7_A_wzESozsPxtC6z7n4fM8VEYwA4Dx...@mail.gmail.com>
	<CALKyTE7ajYdHHrrUaktdXDBgozUFP9g1zxpRwe_3vo-2Cf9...@mail.gmail.com>
	<0ce05902-2cea-4c5f-b027-a5cf48849...@gn8g2000vbb.googlegroups.com>
	<CALKyTE6R1uR1v=506-56amkufU3QZjPAa56f9Fom6sw8v-e...@mail.gmail.com>
	<bf384d45-6500-45f1-ade4-0adc974b4...@p21g2000vby.googlegroups.com>
	<CALKyTE5rxtRi1kxrKw44-ZCJSKQL7QigC9v6FesMSMcSK41...@mail.gmail.com>
	<ccaf774c-eed8-4afe-be46-d253d7ad5...@c30g2000vby.googlegroups.com>
Date: Tue, 8 May 2012 00:08:58 +0100
Message-ID: <CALKyTE6Dq2OT0Bcwa+wZ02PUppLYf2Bk1=vbOtNZwV8K61c...@mail.gmail.com>
Subject: Re: [mongodb-user] Re: MapReduce when field doesn't exist in every document
From: Sam Millman <sam.mill...@gmail.com>
To: mongodb-user@googlegroups.com
Content-Type: multipart/alternative; boundary=20cf302d4990e056a204bf7a5adf

--20cf302d4990e056a204bf7a5adf
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Ok I think this is your problem:

"DateCreated": "Tue, 01 May 2012 16:30:59 GMT -05:00"

I dont think the JS Date object is capable of converting that syntax. You
should use your drivers Date() class to put dates into a ISODate() object
and use the localized syntax within ISO to allow you to represent GMT - 5.

Providing there isn't someting wrong with the reduce, which by the looks of
it there isn't (would require more testing) since it's a simple count and
return hopefully it should just be those dates.

There is one way to check, put a static value into your map for it to emit
on like so:

if (this.hasOwnProperty("SubDoc")) { // As seen:
http://stackoverflow.com/questions/2281633/javascript-isset-equivalent
var day, date; // Lets globally define our variables
for(var row in this.SubDoc){ // For every row in our SubDoc
   if(row.hasOwnProperty("DateCreated")){ // Have we got such a field?

      date =3D Date(row.DateCreated); // convert the date to the JS version

      day =3D date.getFullYear() + =93-=94 +
      date.getMonth() + =93-=93 +
      date.getDate();
      emit({day:  12} , {count:  1});
   }
}

If you get one or more results your know its your dates doing it.
hasOwnProperty is fully supported by spider monkey so it should be nothing
to do with that, otherwise you'd get an error.

On 7 May 2012 23:39, EKTW <erin.wald...@gmail.com> wrote:

> {
>   "SubDoc": [
>     {
>       "_id": "4fa05613c8829e6620fd32ed",
>       "DateCreated": "Tue, 01 May 2012 16:30:59 GMT -05:00"
>     },
>     {
>       "_id": "4fa056150372b50fd47d8c33",
>       "DateCreated": "Tue, 01 May 2012 16:31:01 GMT -05:00"
>     },
>     {
>       "_id": "4fa05615c8829e6620fd34b2",
>       "DateCreated": "Tue, 01 May 2012 16:31:01 GMT -05:00"
>     },
>     {
>       "_id": "4fa05617c8829e597855a168",
>       "DateCreated": "Tue, 01 May 2012 16:31:03 GMT -05:00"
>     }
>   ],
>   "_id": "4fa05612c8829e6620fd32ac"
> }
>
>
> I removed unrelated fields.
>
> On May 7, 5:20 pm, Sam Millman <sam.mill...@gmail.com> wrote:
> > Can you give me an exact dump straight from the Mongo shell of your
> > document?
> >
> > No formatting on your part or anything, a straight copy and paste..
> >
> > On 7 May 2012 23:17, EKTW <erin.wald...@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Tried that, and didn't get an error, but still got no results.
> >
> > > On May 7, 4:09 pm, Sam Millman <sam.mill...@gmail.com> wrote:
> > > > You can do:
> >
> > > > if (this.hasOwnProperty("SubDoc")) { // As seen:
> > >http://stackoverflow.com/questions/2281633/javascript-isset-equivalent
> > > > var day, date; // Lets globally define our variables
> > > > for(var row in this.SubDoc){ // For every row in our SubDoc
> > > >    if(row.hasOwnProperty("DateCreated")){ // Have we got such a
> field?
> >
> > > >       date =3D Date(row.DateCreated); // convert the date to the JS
> version
> >
> > > >       day =3D date.getFullYear() + =93-=94 +
> > > >       date.getMonth() + =93-=93 +
> > > >       date.getDate();
> > > >       emit({day:  day} , {count:  1});
> > > >    }
> >
> > > > }
> >
> > > > But the error states that the date field itself has no properties.
> Which
> > > > means either:
> >
> > > > - You can used: "5/8/2012 1: 15 pm" in full string format without a=
ny
> > > sort
> > > > of ISO container which the JS Date function cannot translate
> > > > - Or the field on the row itself (the date field) is null or non
> existant
> > > > (which we are checking for niow).
> >
> > > > On 7 May 2012 22:02, EKTW <erin.wald...@gmail.com> wrote:
> >
> > > > > Yes, I think that is the problem. There are documents that have n=
o
> > > > > SubDoc, and thus no DateCreated field. That's why I was originall=
y
> > > > > using:
> >
> > > > > if (!this.SubDoc.DateCreated) {
> > > > > return;
> >
> > > > > }
> >
> > > > > Maybe I could try a combination like:
> >
> > > > > if (!this.SubDoc.DateCreated) {
> > > > > var day;
> > > > > for(var row in this.SubDoc){
> >
> > > > > > day =3D row.DateCreated.getFullYear() + =93-=94 +
> > > > > > row.DateCreated.getMonth() + =93-=93 +
> > > > > > row.DateCreated.getDate();
> > > > > > emit({day:  day} , {count:  1});
> > > > > }
> >
> > > > > }
> >
> > > > > On May 7, 3:38 pm, Sam Millman <sam.mill...@gmail.com> wrote:
> > > > > > And yet again looking at your code I realise the "no properties=
"
> > > thing.
> > > > > > That could denote a null field so make sure every field is fill=
ed
> > > before
> > > > > > you try and test on them.
> >
> > > > > > On 7 May 2012 21:36, Sam Millman <sam.mill...@gmail.com> wrote:
> >
> > > > > > > But looking closer at your error I just realised I made a
> mistake
> > > > > myself
> > > > > > > :\ so ignore that message a little.
> >
> > > > > > > What is happening is that the ISODate does not actually work
> like
> > > that.
> >
> > > > > > > I believe in a MR you can do:
> >
> > > > > > > date =3D Date(row.DateCreate);
> >
> > > > > > > Add that to your loop and then try again using date to get th=
e
> > > parts (
> > > > > > >http://www.w3schools.com/js/js_obj_date.asp).
> >
> > > > > > > On 7 May 2012 21:33, Sam Millman <sam.mill...@gmail.com>
> wrote:
> >
> > > > > > >> Yea cos it required some basic JS to make the day variable
> equal
> > > the
> > > > > date.
> >
> > > > > > >> You can fix this by doing:
> >
> > > > > > >> var day;
> > > > > > >> for(var row in this.SubDoc){
> >
> > > > > > >>> day =3D row.DateCreated.getFullYear() + =93-=94 +
> >
> > > > > > >>> row.DateCreated.getMonth() + =93-=93 +
> > > > > > >>> row.DateCreated.getDate();
> >
> > > > > > >>> emit({day:  day} , {count:  1});
> >
> > > > > > >> }
> >
> > > > > > >> But MongoDB MR runs on  a JS engine known as spider monkey
> (it's
> > > what
> > > > > > >> Firefox uses). I would recommend you read some JavaScript
> basics
> > > over
> > > > > at:
> > > > > > >>http://www.w3schools.com/js/. You will really need to know
> your
> > > JS to
> > > > > > >> write further MRs.
> >
> > > > > > >> On 7 May 2012 21:29, EKTW <erin.wald...@gmail.com> wrote:
> >
> > > > > > >>> Thanks, Sam.
> >
> > > > > > >>> I tried that, and got my original "map invoke failed: JS
> Error:
> > > > > > >>> TypeError: row.DateCreated has no properties" error message
> that
> > > I
> > > > > > >>> believe has to deal with not every document having somethin=
g
> in
> > > > > > >>> SubDoc. Is there a way to work in a fix for that as well?
> >
> > > > > > >>> On May 7, 3:11 pm, Sam Millman <sam.mill...@gmail.com>
> wrote:
> > > > > > >>> > Try something closer to:
> >
> > > > > > >>> > for(var row in this.SubDoc){
> >
> > > > > > >>> > > row.DateCreated.getFullYear() + =93-=94 +
> > > > > > >>> > > row.DateCreated.getMonth() + =93-=93 +
> > > > > > >>> > > row.DateCreated.getDate();
> > > > > > >>> > > emit({day:  day} , {count:  1});
> >
> > > > > > >>> > }
> >
> > > > > > >>> > On 7 May 2012 20:33, EKTW <erin.wald...@gmail.com> wrote:
> >
> > > > > > >>> > > I tried writing the map like this:
> >
> > > > > > >>> > > map =3D function() {
> > > > > > >>> > > for (var q in this.SubDoc.DateCreated) {
> > > > > > >>> > >  day =3D this.SubDoc.DateCreated[q].getFullYear() + =93=
-=94 +
> > > > > > >>> > > this.SubDoc.DateCreated[q].getMonth() + =93-=93 +
> > > > > > >>> > > this.SubDoc.DateCreated[q].getDate();
> > > > > > >>> > >  emit({day:  day} , {count:  1});
> > > > > > >>> > >  }
> > > > > > >>> > > }
> >
> > > > > > >>> > > and still got no results.
> >
> > > > > > >>> > > Thanks so much for your help!
> >
> > > > > > >>> > > On May 7, 2:16 pm, EKTW <erin.wald...@gmail.com> wrote:
> > > > > > >>> > > > That definitely sounds like what I want to do. Do you
> have
> > > an
> > > > > > >>> example
> > > > > > >>> > > > of how I would write that?
> >
> > > > > > >>> > > > On May 7, 2:12 pm, Sam Millman <sam.mill...@gmail.com=
>
> > > wrote:
> >
> > > > > > >>> > > > > The way you are accessing your arrays is the proble=
m:
> >
> > > > > > >>> > > > > if (!this.SubDoc.DateCreated) {
> > > > > > >>> > > > > return;
> >
> > > > > > >>> > > > > }
> >
> > > > > > >>> > > > > That actually means get the property of DateCreated
> that
> > > > > exists
> > > > > > >>> in
> > > > > > >>> > > SubDoc
> > > > > > >>> > > > > (only once) that exists in this doc (only once
> again).
> >
> > > > > > >>> > > > > What you actually wanna do is loop across SubDoc
> testing
> > > each
> > > > > > >>> row with
> > > > > > >>> > > what
> > > > > > >>> > > > > you have written for your MR since the map will onl=
y
> > > loop the
> > > > > > >>> root doc
> > > > > > >>> > > not
> > > > > > >>> > > > > subdocuments by default.
> >
> > > > > > >>> > > > > On 7 May 2012 19:54, EKTW <erin.wald...@gmail.com>
> > > wrote:
> >
> > > > > > >>> > > > > > The document has a lot of fields, but basically t=
he
> > > > > relevant
> > > > > > >>> > > structure
> > > > > > >>> > > > > > looks something like this:
> >
> > > > > > >>> > > > > > _id: 12345
> > > > > > >>> > > > > > SubDoc[2]
> > > > > > >>> > > > > >  0
> > > > > > >>> > > > > >   _id: 234
> > > > > > >>> > > > > >   DateCreated: 5/7/2012 3:30 pm
> > > > > > >>> > > > > >  1
> > > > > > >>> > > > > >   _id: 456
> > > > > > >>> > > > > >   DateCreated: 5/8/2012 1: 15 pm
> >
> > > > > > >>> > > > > > _id: 56789
> > > > > > >>> > > > > > SubDoc[1]
> > > > > > >>> > > > > >  0
> > > > > > >>> > > > > >   _id: 632
> > > > > > >>> > > > > >   DateCreated: 5/6/2012 2:15 am
> >
> > > > > > >>> > > > > > and this is the mapreduce I'm trying to use:
> >
> > > > > > >>> > > > > > map =3D function() {
> > > > > > >>> > > > > > if (!this.SubDoc.DateCreated) {
> > > > > > >>> > > > > > return;
> > > > > > >>> > > > > > }
> > > > > > >>> > > > > >  day =3D this.SubDoc.DateCreated.getFullYear() + =
=93-=94
> +
> > > > > > >>> > > > > > this.SubDoc.DateCreated.getMonth() + =93-=93 +
> > > > > > >>> > > > > > this.SubDoc.DateCreated.getDate();
> > > > > > >>> > > > > >  emit({day:  day} , {count:  1});
> > > > > > >>> > > > > >  }
> >
> > > > > > >>> > > > > > reduce =3D function(key, values) {
> > > > > > >>> > > > > >  var count =3D 0;
> > > > > > >>> > > > > > values.forEach(function(mr) {count +=3D mr.count;=
});
> > > > > > >>> > > > > >  return {count: count};
> > > > > > >>> > > > > >  }
> >
> > > > > > >>> > > > > >  two_weeks_ago =3D new Date(Date.now() =96
> > > 60*60*24*14*1000);
> > > > > > >>> > > > > >  results =3D db.DocCollection.mapReduce(map, redu=
ce,
> > > {out:
> > > > > > >>> =91test=92,
> > > > > > >>> > > > > > query: {=93SubDoc.DateCreated=94: {$gt:
> two_weeks_ago}}});
> >
> > > > > > >>> > > > > > On May 7, 1:26 pm, Scott Hernandez <
> > > > > scotthernan...@gmail.com>
> > > > > > >>> wrote:
> > > > > > >>> > > > > > > Can you provide a document and the reduce you
> want to
> > > > > use?
> >
> > > > > > >>> > > > > > > On Mon, May 7, 2012 at 11:21 AM, EKTW <
> > > > > > >>> erin.wald...@gmail.com>
> > > > > > >>> > > wrote:
> > > > > > >>> > > > > > > > Thank you, I was able to get that part figure=
d
> out,
> > > > > but am
> > > > > > >>> now
> > > > > > >>> > > facing
> > > > > > >>> > > > > > > > another problem. I'm trying to use mapreduce =
to
> > > get the
> > > > > > >>> number of
> > > > > > >>> > > > > > > > embedded documents created per day, and any
> > > document
> > > > > in the
> > > > > > >>> > > collection
> > > > > > >>> > > > > > > > may have several of these embedded documents.
> So
> > > the
> > > > > > >>> fields in my
> > > > > > >>> > > > > > > > document look like:
> >
> > > > > > >>> > > > > > > > blah.0.DateCreated
> > > > > > >>> > > > > > > > blah.1.DateCreated
> > > > > > >>> > > > > > > > blah.2.DateCreated
> >
> > > > > > >>> > > > > > > > and so on. I tried using blah.DateCreated and
> it
> > > > > worked,
> > > > > > >>> but I
> > > > > > >>> > > got no
> > > > > > >>> > > > > > > > results. Is there a way to use mapreduce for
> this
> > > > > > >>> situation?
> >
> > > > > > >>> > > > > > > > thanks!
> >
> > > > > > >>> > > > > > > > On May 7, 12:38 pm, Scott Hernandez <
> > > > > > >>> scotthernan...@gmail.com>
> > > > > > >>> > > wrote:
> > > > > > >>> > > > > > > >> Yes, you need to check for the fields first.
> >
> > > > > > >>> > > > > > > >> if(obj.field) {
> > > > > > >>> > > > > > > >> // do something with field
> >
> > > > > > >>> > > > > > > >> }
> > > > > > >>> > > > > > > >> On Mon, May 7, 2012 at 10:15 AM, EKTW <
> > > > > > >>> erin.wald...@gmail.com>
> > > > > > >>> > > wrote:
> > > > > > >>> > > > > > > >> > Is it possible to do a mapreduce when a
> field
> > > > > doesn't
> > > > > > >>> exist
> > > > > > >>> > > in every
> > > > > > >>> > > > > > > >> > document? I'm getting a "map invoke failed=
"
> > > error
> > > > > > >>> saying my
> > > > > > >>> > > field
> >
> > ...
> >
> > read more =BB
>
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=3Den.
>
>

--20cf302d4990e056a204bf7a5adf
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Ok I think this is your problem:<br><br>&quot;DateCreated&quot;: &quot;Tue,=
 01 May 2012 16:30:59 GMT -05:00&quot;<br><br>I dont think the JS Date obje=
ct is capable of converting that syntax. You should use your drivers Date()=
 class to put dates into a ISODate() object and use the localized syntax wi=
thin ISO to allow you to represent GMT - 5.<br>
<br>Providing there isn&#39;t someting wrong with the reduce, which by the =
looks of it there isn&#39;t (would require more testing) since it&#39;s a s=
imple count and return hopefully it should just be those dates.<br><br>
There is one way to check, put a static value into your map for it to emit =
on like so:<br><br>if (this.hasOwnProperty(&quot;SubDoc&quot;)) { // As see=
n: <a href=3D"http://stackoverflow.com/questions/2281633/javascript-isset-e=
quivalent" target=3D"_blank">http://stackoverflow.com/questions/2281633/jav=
ascript-isset-equivalent</a><br>


<div id=3D":x9"><div>var day, date; // Lets globally define our variables<b=
r>
for(var row in this.SubDoc){ // For every row in our SubDoc<br>=A0=A0 if(ro=
w.hasOwnProperty(&quot;DateCreated&quot;)){ // Have we got such a field?<br=
>=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0 date =3D Date(row.DateCreated); // con=
vert the date to the JS version<br>

<br>=A0=A0=A0=A0=A0 day =3D date.getFullYear() + =93-=94 +<br>=A0=A0=A0=A0=
=A0 date.getMonth() + =93-=93 +<br>=A0=A0=A0=A0=A0 date.getDate();<br>
</div><div class=3D"im">=A0=A0=A0=A0=A0 emit({day:=A0 12} , {count: =A01});=
<br>=A0=A0 }<br>
}</div></div><br>If you get one or more results your know its your dates do=
ing it. hasOwnProperty is fully supported by spider monkey so it should be =
nothing to do with that, otherwise you&#39;d get an error.<br><br><div clas=
s=3D"gmail_quote">
On 7 May 2012 23:39, EKTW <span dir=3D"ltr">&lt;<a href=3D"mailto:erin.wald=
r...@gmail.com" target=3D"_blank">erin.wald...@gmail.com</a>&gt;</span> wrot=
e:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex">
{<br>
=A0 &quot;SubDoc&quot;: [<br>
=A0 =A0 {<br>
=A0 =A0 =A0 &quot;_id&quot;: &quot;4fa05613c8829e6620fd32ed&quot;,<br>
=A0 =A0 =A0 &quot;DateCreated&quot;: &quot;Tue, 01 May 2012 16:30:59 GMT -0=
5:00&quot;<br>
=A0 =A0 },<br>
=A0 =A0 {<br>
=A0 =A0 =A0 &quot;_id&quot;: &quot;4fa056150372b50fd47d8c33&quot;,<br>
=A0 =A0 =A0 &quot;DateCreated&quot;: &quot;Tue, 01 May 2012 16:31:01 GMT -0=
5:00&quot;<br>
=A0 =A0 },<br>
=A0 =A0 {<br>
=A0 =A0 =A0 &quot;_id&quot;: &quot;4fa05615c8829e6620fd34b2&quot;,<br>
=A0 =A0 =A0 &quot;DateCreated&quot;: &quot;Tue, 01 May 2012 16:31:01 GMT -0=
5:00&quot;<br>
=A0 =A0 },<br>
=A0 =A0 {<br>
=A0 =A0 =A0 &quot;_id&quot;: &quot;4fa05617c8829e597855a168&quot;,<br>
=A0 =A0 =A0 &quot;DateCreated&quot;: &quot;Tue, 01 May 2012 16:31:03 GMT -0=
5:00&quot;<br>
=A0 =A0 }<br>
=A0 ],<br>
=A0 &quot;_id&quot;: &quot;4fa05612c8829e6620fd32ac&quot;<br>
}<br>
<br>
<br>
I removed unrelated fields.<br>
<div class=3D"im HOEnZb"><br>
On May 7, 5:20=A0pm, Sam Millman &lt;<a href=3D"mailto:sam.mill...@gmail.co=
m">sam.mill...@gmail.com</a>&gt; wrote:<br>
&gt; Can you give me an exact dump straight from the Mongo shell of your<br=
>
&gt; document?<br>
&gt;<br>
&gt; No formatting on your part or anything, a straight copy and paste..<br=
>
&gt;<br>
</div><div class=3D"HOEnZb"><div class=3D"h5">&gt; On 7 May 2012 23:17, EKT=
W &lt;<a href=3D"mailto:erin.wald...@gmail.com">erin.wald...@gmail.com</a>&=
gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; &gt; Tried that, and didn&#39;t get an error, but still got no results=
.<br>
&gt;<br>
&gt; &gt; On May 7, 4:09 pm, Sam Millman &lt;<a href=3D"mailto:sam.mill...@=
gmail.com">sam.mill...@gmail.com</a>&gt; wrote:<br>
&gt; &gt; &gt; You can do:<br>
&gt;<br>
&gt; &gt; &gt; if (this.hasOwnProperty(&quot;SubDoc&quot;)) { // As seen:<b=
r>
&gt; &gt;<a href=3D"http://stackoverflow.com/questions/2281633/javascript-i=
sset-equivalent" target=3D"_blank">http://stackoverflow.com/questions/22816=
33/javascript-isset-equivalent</a><br>
&gt; &gt; &gt; var day, date; // Lets globally define our variables<br>
&gt; &gt; &gt; for(var row in this.SubDoc){ // For every row in our SubDoc<=
br>
&gt; &gt; &gt; =A0 =A0if(row.hasOwnProperty(&quot;DateCreated&quot;)){ // H=
ave we got such a field?<br>
&gt;<br>
&gt; &gt; &gt; =A0 =A0 =A0 date =3D Date(row.DateCreated); // convert the d=
ate to the JS version<br>
&gt;<br>
&gt; &gt; &gt; =A0 =A0 =A0 day =3D date.getFullYear() + =93-=94 +<br>
&gt; &gt; &gt; =A0 =A0 =A0 date.getMonth() + =93-=93 +<br>
&gt; &gt; &gt; =A0 =A0 =A0 date.getDate();<br>
&gt; &gt; &gt; =A0 =A0 =A0 emit({day: =A0day} , {count: =A01});<br>
&gt; &gt; &gt; =A0 =A0}<br>
&gt;<br>
&gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; But the error states that the date field itself has no prope=
rties. Which<br>
&gt; &gt; &gt; means either:<br>
&gt;<br>
&gt; &gt; &gt; - You can used: &quot;5/8/2012 1: 15 pm&quot; in full string=
 format without any<br>
&gt; &gt; sort<br>
&gt; &gt; &gt; of ISO container which the JS Date function cannot translate=
<br>
&gt; &gt; &gt; - Or the field on the row itself (the date field) is null or=
 non existant<br>
&gt; &gt; &gt; (which we are checking for niow).<br>
&gt;<br>
&gt; &gt; &gt; On 7 May 2012 22:02, EKTW &lt;<a href=3D"mailto:erin.wald...=
@gmail.com">erin.wald...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; Yes, I think that is the problem. There are documents t=
hat have no<br>
&gt; &gt; &gt; &gt; SubDoc, and thus no DateCreated field. That&#39;s why I=
 was originally<br>
&gt; &gt; &gt; &gt; using:<br>
&gt;<br>
&gt; &gt; &gt; &gt; if (!this.SubDoc.DateCreated) {<br>
&gt; &gt; &gt; &gt; return;<br>
&gt;<br>
&gt; &gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; Maybe I could try a combination like:<br>
&gt;<br>
&gt; &gt; &gt; &gt; if (!this.SubDoc.DateCreated) {<br>
&gt; &gt; &gt; &gt; var day;<br>
&gt; &gt; &gt; &gt; for(var row in this.SubDoc){<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; day =3D row.DateCreated.getFullYear() + =93-=94 +<=
br>
&gt; &gt; &gt; &gt; &gt; row.DateCreated.getMonth() + =93-=93 +<br>
&gt; &gt; &gt; &gt; &gt; row.DateCreated.getDate();<br>
&gt; &gt; &gt; &gt; &gt; emit({day: =A0day} , {count: =A01});<br>
&gt; &gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; On May 7, 3:38 pm, Sam Millman &lt;<a href=3D"mailto:sa=
m.mill...@gmail.com">sam.mill...@gmail.com</a>&gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; And yet again looking at your code I realise the &=
quot;no properties&quot;<br>
&gt; &gt; thing.<br>
&gt; &gt; &gt; &gt; &gt; That could denote a null field so make sure every =
field is filled<br>
&gt; &gt; before<br>
&gt; &gt; &gt; &gt; &gt; you try and test on them.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; On 7 May 2012 21:36, Sam Millman &lt;<a href=3D"ma=
ilto:sam.mill...@gmail.com">sam.mill...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; But looking closer at your error I just reali=
sed I made a mistake<br>
&gt; &gt; &gt; &gt; myself<br>
&gt; &gt; &gt; &gt; &gt; &gt; :\ so ignore that message a little.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; What is happening is that the ISODate does no=
t actually work like<br>
&gt; &gt; that.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; I believe in a MR you can do:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; date =3D Date(row.DateCreate);<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; Add that to your loop and then try again usin=
g date to get the<br>
&gt; &gt; parts (<br>
&gt; &gt; &gt; &gt; &gt; &gt;<a href=3D"http://www.w3schools.com/js/js_obj_=
date.asp" target=3D"_blank">http://www.w3schools.com/js/js_obj_date.asp</a>=
).<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; On 7 May 2012 21:33, Sam Millman &lt;<a href=
=3D"mailto:sam.mill...@gmail.com">sam.mill...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; Yea cos it required some basic JS to make=
 the day variable equal<br>
&gt; &gt; the<br>
&gt; &gt; &gt; &gt; date.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; You can fix this by doing:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; var day;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; for(var row in this.SubDoc){<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; day =3D row.DateCreated.getFullYear()=
 + =93-=94 +<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; row.DateCreated.getMonth() + =93-=93 =
+<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; row.DateCreated.getDate();<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; emit({day: =A0day} , {count: =A01});<=
br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; But MongoDB MR runs on =A0a JS engine kno=
wn as spider monkey (it&#39;s<br>
&gt; &gt; what<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; Firefox uses). I would recommend you read=
 some JavaScript basics<br>
&gt; &gt; over<br>
&gt; &gt; &gt; &gt; at:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;<a href=3D"http://www.w3schools.com/js/" t=
arget=3D"_blank">http://www.w3schools.com/js/</a>. You will really need to =
know your<br>
&gt; &gt; JS to<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; write further MRs.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; On 7 May 2012 21:29, EKTW &lt;<a href=3D"=
mailto:erin.wald...@gmail.com">erin.wald...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; Thanks, Sam.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; I tried that, and got my original &qu=
ot;map invoke failed: JS Error:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; TypeError: row.DateCreated has no pro=
perties&quot; error message that<br>
&gt; &gt; I<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; believe has to deal with not every do=
cument having something in<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; SubDoc. Is there a way to work in a f=
ix for that as well?<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; On May 7, 3:11 pm, Sam Millman &lt;<a=
 href=3D"mailto:sam.mill...@gmail.com">sam.mill...@gmail.com</a>&gt; wrote:=
<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; Try something closer to:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; for(var row in this.SubDoc){<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; row.DateCreated.getFullYear=
() + =93-=94 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; row.DateCreated.getMonth() =
+ =93-=93 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; row.DateCreated.getDate();<=
br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; emit({day: =A0day} , {count=
: =A01});<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; On 7 May 2012 20:33, EKTW &lt;<a=
 href=3D"mailto:erin.wald...@gmail.com">erin.wald...@gmail.com</a>&gt; wrot=
e:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; I tried writing the map lik=
e this:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; map =3D function() {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; for (var q in this.SubDoc.D=
ateCreated) {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; =A0day =3D this.SubDoc.Date=
Created[q].getFullYear() + =93-=94 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; this.SubDoc.DateCreated[q].=
getMonth() + =93-=93 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; this.SubDoc.DateCreated[q].=
getDate();<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; =A0emit({day: =A0day} , {co=
unt: =A01});<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; =A0}<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; and still got no results.<b=
r>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; Thanks so much for your hel=
p!<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; On May 7, 2:16 pm, EKTW &lt=
;<a href=3D"mailto:erin.wald...@gmail.com">erin.wald...@gmail.com</a>&gt; w=
rote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; That definitely sounds=
 like what I want to do. Do you have<br>
&gt; &gt; an<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; example<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; of how I would write t=
hat?<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; On May 7, 2:12 pm, Sam=
 Millman &lt;<a href=3D"mailto:sam.mill...@gmail.com">sam.mill...@gmail.com=
</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; The way you are a=
ccessing your arrays is the problem:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; if (!this.SubDoc.=
DateCreated) {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; return;<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; }<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; That actually mea=
ns get the property of DateCreated that<br>
&gt; &gt; &gt; &gt; exists<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; in<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; SubDoc<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; (only once) that =
exists in this doc (only once again).<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; What you actually=
 wanna do is loop across SubDoc testing<br>
&gt; &gt; each<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; row with<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; what<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; you have written =
for your MR since the map will only<br>
&gt; &gt; loop the<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; root doc<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; not<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; subdocuments by d=
efault.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; On 7 May 2012 19:=
54, EKTW &lt;<a href=3D"mailto:erin.wald...@gmail.com">erin.wald...@gmail.c=
om</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; The document=
 has a lot of fields, but basically the<br>
&gt; &gt; &gt; &gt; relevant<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; structure<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; looks someth=
ing like this:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; _id: 12345<b=
r>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; SubDoc[2]<br=
>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A00<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 _id: 234=
<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 DateCrea=
ted: 5/7/2012 3:30 pm<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A01<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 _id: 456=
<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 DateCrea=
ted: 5/8/2012 1: 15 pm<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; _id: 56789<b=
r>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; SubDoc[1]<br=
>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A00<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 _id: 632=
<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0 DateCrea=
ted: 5/6/2012 2:15 am<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; and this is =
the mapreduce I&#39;m trying to use:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; map =3D func=
tion() {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; if (!this.Su=
bDoc.DateCreated) {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; return;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; }<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0day =3D t=
his.SubDoc.DateCreated.getFullYear() + =93-=94 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; this.SubDoc.=
DateCreated.getMonth() + =93-=93 +<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; this.SubDoc.=
DateCreated.getDate();<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0emit({day=
: =A0day} , {count: =A01});<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0}<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; reduce =3D f=
unction(key, values) {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0var count=
 =3D 0;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; values.forEa=
ch(function(mr) {count +=3D mr.count;});<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0return {c=
ount: count};<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0}<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0two_weeks=
_ago =3D new Date(Date.now() =96<br>
&gt; &gt; 60*60*24*14*1000);<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; =A0results =
=3D db.DocCollection.mapReduce(map, reduce,<br>
&gt; &gt; {out:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; =91test=92,<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; query: {=93S=
ubDoc.DateCreated=94: {$gt: two_weeks_ago}}});<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; On May 7, 1:=
26 pm, Scott Hernandez &lt;<br>
&gt; &gt; &gt; &gt; <a href=3D"mailto:scotthernan...@gmail.com">scotthernan=
....@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; Can you=
 provide a document and the reduce you want to<br>
&gt; &gt; &gt; &gt; use?<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; On Mon,=
 May 7, 2012 at 11:21 AM, EKTW &lt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; <a href=3D"mailto:erin.wald...@gmail.=
com">erin.wald...@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; Th=
ank you, I was able to get that part figured out,<br>
&gt; &gt; &gt; &gt; but am<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; now<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; facing<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; an=
other problem. I&#39;m trying to use mapreduce to<br>
&gt; &gt; get the<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; number of<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; em=
bedded documents created per day, and any<br>
&gt; &gt; document<br>
&gt; &gt; &gt; &gt; in the<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; collection<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; ma=
y have several of these embedded documents. So<br>
&gt; &gt; the<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; fields in my<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; do=
cument look like:<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; bl=
ah.0.DateCreated<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; bl=
ah.1.DateCreated<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; bl=
ah.2.DateCreated<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; an=
d so on. I tried using blah.DateCreated and it<br>
&gt; &gt; &gt; &gt; worked,<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; but I<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; got no<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; re=
sults. Is there a way to use mapreduce for this<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; situation?<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; th=
anks!<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt; On=
 May 7, 12:38 pm, Scott Hernandez &lt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; <a href=3D"mailto:scotthernan...@gmai=
l.com">scotthernan...@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; Yes, you need to check for the fields first.<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; if(obj.field) {<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; // do something with field<br>
&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; }<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; On Mon, May 7, 2012 at 10:15 AM, EKTW &lt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; <a href=3D"mailto:erin.wald...@gmail.=
com">erin.wald...@gmail.com</a>&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; &gt; Is it possible to do a mapreduce when a field<br>
&gt; &gt; &gt; &gt; doesn&#39;t<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; exist<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; in every<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; &gt; &gt; &gt; &gt; &gt;&gt=
; &gt; document? I&#39;m getting a &quot;map invoke failed&quot;<br>
&gt; &gt; error<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; saying my<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;&gt; &gt; &gt; field<br>
&gt;<br>
</div></div><div class=3D"HOEnZb"><div class=3D"h5">&gt; ...<br>
&gt;<br>
&gt; read more =BB<br>
<br>
--<br>
You received this message because you are subscribed to the Google Groups &=
quot;mongodb-user&quot; group.<br>
To post to this group, send email to <a href=3D"mailto:mongodb-user@googleg=
roups.com">mongodb-user@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href=3D"mailto:mongodb-use=
r%2Bunsubscribe@googlegroups.com">mongodb-user+unsubscribe@googlegroups.com=
</a>.<br>
For more options, visit this group at <a href=3D"http://groups.google.com/g=
roup/mongodb-user?hl=3Den" target=3D"_blank">http://groups.google.com/group=
/mongodb-user?hl=3Den</a>.<br>
<br>
</div></div></blockquote></div><br>

--20cf302d4990e056a204bf7a5adf--