Re: Comparing dates inside of mapreduce

From: Asya Kamsky <asya@xxxxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Wed, 27 Apr 2016 14:01:27 -0700
Why ads?
Well, that would certainly explain why comparison isn't returning the
expected result.

As far as doing aggregation here, I think you just need to do
appropriate $match of dates being within range.  Probably you will
have some complex $or predicate if you need to compare both current
and historical date ranges.

Asya


On Tue, Apr 26, 2016 at 2:40 AM, Vegar Vikan <vegar@xxxxxxxxxx> wrote:
Wow - I think I fund the issue.

Visual Studio decided to 'clean up' my sample data file, changing
ISODate("...") into "ISODate(\"....\")".

So what I have believed is ISODate fields is actually string fields....


Anyway - would love to get some input on alternatives.


On Tuesday, April 26, 2016 at 8:53:45 AM UTC+2, Vegar Vikan wrote:

No, I'm not sure I want to use mapreduce, but that's the solution I have
found.

The data structure is not the best I guess....


The document has a structure similar to

{
    CurrentThing: {
        StartDate: ISODate(".....")
    },
    HistoryOfThings: [
        {
             StartDate: ISODate("...."),
             EndDate: ISODate("....")
        },
        {
             StartDate: ISODate("...."),
             EndDate: ISODate("....")
        }
   ]

}


Some events leads to the 'CurrentThing' being moved to the
'HistoryOfThings' and the 'CurrentThing' being initialized with a new thing.

Now, I need a list of every 'Thing' for a given period, grouped on a
property common across different documents.

Aggregation would be my first guess, but even though I can $unwind the
'HistoryOfThings'-array, I'm not sure how to handle the
'CurrentThing'-subdocument.

So I ended up doing map reduce, and want to emit for each 'Thing'
according to the daterange given.

Any other suggestions is welcome, but I'm still curious why comparing
dates didn't go as expected :-)




On Tuesday, April 26, 2016 at 2:37:34 AM UTC+2, Asya Kamsky wrote:

Are you sure you want to be using mapReduce?   Most things that people
do in mapReduce can be done faster in aggregation framework.   Can you
give a bit more context for your problem?  Are you emitting different
values depending on relationship between "created" and "start"?

Asya


On Mon, Apr 25, 2016 at 5:01 PM, Vegar Vikan <ve...@xxxxxxxxxx> wrote:
I posted this question on stackoverflow, but it didn't get any
attention, so
I try here as well...

I have a map function in a mapreduce query where I try to compare a
couple
of dates.

Lets say that the documents contains a property 'Created' with type
ISODate:

{
  Created: ISODate("2016-01-01T12:00:00.000+0000")
}

In my map/reduce method, I pass a date through the scope:

{
   start: ISODate("2015-01-01T12:00:00.000+0000")
}

and in my map method, I print out the following

function() {
   print(this.Created);
   print(start);
   print(this.Created > start);
}

I'll get the following output in my log:

2016-04-25T16:19:04.921+0200 I -        [conn129]
ISODate("2016-01-01T12:00:00.000+0000")
2016-04-25T16:19:04.922+0200 I -        [conn129] Sat Jan 01 2015
13:00:00
GMT+0100 (Vest-Europa (normaltid))
2016-04-25T16:19:04.922+0200 I -        [conn129] false


Why is the dates printed differently?
How can I compare the start-date with the created date?

regars,
-Vegar

--
You received this message because you are subscribed to the Google
Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google
Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send
an
email to mongodb-user...@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongod...@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit

https://groups.google.com/d/msgid/mongodb-user/9fc028b4-3f48-4dbb-b76b-9b017eec9adc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

--
You received this message because you are subscribed to the Google Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1bcf45b2-90e1-44c6-a541-a508b2e2ec7e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



-- 
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJBz4pEQHZk5tkxAYvLuzhrmew%2BTOnwZeZE9VN_N0vaC-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Why ads?