Skip to content
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

Add support for db.collection.distinctDate #9

Open
quique0194 opened this issue May 15, 2019 · 0 comments
Open

Add support for db.collection.distinctDate #9

quique0194 opened this issue May 15, 2019 · 0 comments

Comments

@quique0194
Copy link

Imagine you have a collection with a timestamp property, and you want to know quickly what dates are those object from.

I leave a piece of code to start here:

db.collection.aggregate([
    { "$project": {
         "year": { "$year": "$created" },
         "month": { "$month": "$created" },
         "day": { "$dayOfMonth": "$created" }
    }},
    { "$group": {
        "_id": null,
        "distinctDate": { "$addToSet": { "year": "$year", "month": "$month", "day": "$day" }}
    }}
])

It could also be possible to add a distinctAndCountDate shortcut, it would be extremely useful for some scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant