New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing user createdAt date as an integer #1228

Closed
ryw opened this Issue Jul 17, 2013 · 4 comments

Comments

Projects
None yet
4 participants
@ryw
Contributor

ryw commented Jul 17, 2013

In accounts-base/accounts_server.js, Meteor stores the createdAt date using +(new Date). The date is stored in MongoDB as an integer.

I'm trying to generate some basic statistics on user creation, using the following aggregation query:

db.users.aggregate(
  { $project:
    { day: { $dayOfYear: new Date('$createdAt') } }
  },
  { $group: 
    { _id: { day: 1 }, total: { $sum: 1 } }
  }
)

However, it doesn't seem that Mongo supports casting during the aggregation query. I get Jan 1, 1970 for all entries.

If I store the a date using new Date() (an ISODate) then the query works.

db.users.aggregate( { $project: { day: {$dayOfYear: '$createdAt'} } })
  1. Am I missing some way to get an aggregation query to work with the date field as it is?
  2. It's unclear to me whether aggregation framework can be used server side in Meteor presently. Are there any limitations in Meteor (server-side) compared to what should work in Mongo console?
@glasser

This comment has been minimized.

Member

glasser commented Jul 26, 2013

Good point. This is because we used to not correctly convert JavaScript Dates into the appropriate Mongo type. Now that we support that (with EJSON), this would be a good change. Care to send a pull request fixing this (and ideally auditing the rest of the codebase for similar issues)?

@ryw

This comment has been minimized.

Contributor

ryw commented Jul 27, 2013

Pull requested - #1251 - Added my query to fix the data in History.md - not sure if that's the right thing to do, but developers will want to update existing production data to get dates all in same format.

@estark37

This comment has been minimized.

Contributor

estark37 commented Aug 21, 2013

Fixed on devel, thanks @ryw!

@estark37 estark37 closed this Aug 21, 2013

@timhaines

This comment has been minimized.

Contributor

timhaines commented Aug 21, 2013

We'd decided to run with integer dates largely based off Meteor's lead. I guess we have a migration ahead of us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment