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

TransactionRequiredException Executing an update/delete query

I am not sure if this will help your situation (that is if it stills exists), however, after scouring the web for a similar issue. I was creating a native query from a persistence EntityManager to perform an update. Query query = entityManager.createNativeQuery(queryString); I was receiving the following error: caused by: javax.persistence.TransactionRequiredException: Executing an update/delete … Read more

Dump Mongo Collection into JSON format

Mongo includes a mongoexport utility (see docs) which can dump a collection. This utility uses the native libmongoclient and is likely the fastest method. mongoexport -d <database> -c <collection_name> Also helpful: -o: write the output to file, otherwise standard output is used (docs) –jsonArray: generates a valid json document, instead of one json object per … Read more

How can I list all collections in the MongoDB shell?

You can do… JavaScript (shell): db.getCollectionNames() Node.js: db.listCollections() Non-JavaScript (shell only): show collections The reason I call that non-JavaScript is because: $ mongo prodmongo/app –eval “show collections” MongoDB shell version: 3.2.10 connecting to: prodmongo/app 2016-10-26T19:34:34.886-0400 E QUERY [thread1] SyntaxError: missing ; before statement @(shell eval):1:5 $ mongo prodmongo/app –eval “db.getCollectionNames()” MongoDB shell version: 3.2.10 connecting … Read more