Group and count by month

You need to use the $month keyword in your group. Your new Date().getMonth() call will only happen once, and will try and create a month out of the string “$bookingdatetime”. db.booking.aggregate([ {$group: { _id: {$month: “$bookingdatetime”}, numberofbookings: {$sum: 1} }} ]);

How to I get Spring-Data-MongoDB to validate my objects?

First make sure that you have JSR-303 validator on classpath, for example: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.2.0.Final</version> </dependency> If you use Java config, the way to go is to create 2 beans: @Bean public ValidatingMongoEventListener validatingMongoEventListener() { return new ValidatingMongoEventListener(validator()); } @Bean public LocalValidatorFactoryBean validator() { return new LocalValidatorFactoryBean(); } Voilà! Validation is working now.

How to create a Mongo Docker Image with default collections and data?

The problem was that information could not be saved on /db/data, so I’ve created a solution creating my own data directory. # Parent Dockerfile https://github.com/docker-library/mongo/blob/982328582c74dd2f0a9c8c77b84006f291f974c3/3.0/Dockerfile FROM mongo:latest # Modify child mongo to use /data/db2 as dbpath (because /data/db wont persist the build) RUN mkdir -p /data/db2 \ && echo “dbpath = /data/db2” > /etc/mongodb.conf \ … Read more

Mongo $in operator performance

It can be fairly efficient with small lists (hard to say what small is, but at least into the tens/hundreds) for $in. It does not work like app-engine since mongodb has actual btree indexes and isn’t a column store like bigtable. With $in it will skip around in the index to find the matching documents, … Read more

How to remove duplicates based on a key in Mongodb?

This answer is obsolete¬†: the dropDups option was removed in MongoDB 3.0, so a different approach will be required in most cases. For example, you could use aggregation as suggested on: MongoDB duplicate documents even after adding unique key. If you are certain that the source_references.key identifies duplicate records, you can ensure a unique index … Read more

MongoDB aggregate within daily grouping [duplicate]

In Mongo 2.8 RC2 there is a new data aggregation operator: $dateToString which can be used to group by a day and simply have a “YYYY-MM-DD” in the result: Example from the documentation: db.sales.aggregate( [ { $project: { yearMonthDay: { $dateToString: { format: “%Y-%m-%d”, date: “$date” } }, time: { $dateToString: { format: “%H:%M:%S:%L”, date: … Read more

Is there a simple way to export the data from a meteor deployed app?

To get the URL for your deployed site at meteor.com use the command (you may need to provide your site password if you password protected it): meteor mongo –url YOURSITE.meteor.com Which will return something like : mongodb://client:[email protected]:27017/YOURSITE_meteor_com Which you can give to a program like mongodump mongodump -u client -h sky.member1.mongolayer.com:27017 -d YOURSITE_meteor_com\ -p PASSWORD … Read more