Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

MongoDB Java Driver Aggregate extension

Maintainers

  • David M. Carr david@carrclan.us

WARNING: This is an experimental extension. Between versions, there may be changes that are not backwards compatible. When there's a reasonable alternative to this extension bundled in the MongoDB Java Driver itself, all maintenance of this extension will cease.

This is an extension to the MongoDB Java Driver to allow for easier syntax for working with the Aggregation Framework. It is available for free under the Apache License, Version 2.0. Releases are available from the extension homepage and from Maven Central.

For example, without the extension, a simple aggregate command in Groovy might look like this:

def output = collection.aggregate(
        new BasicDBObject('$match', new BasicDBObject('_id.demoId': new ObjectId(demoId))),
        new BasicDBObject('$unwind', '$attributes'),
        new BasicDBObject('$match', new BasicDBObject('attributes.id', attributeId)),
        new BasicDBObject('$group', new BasicDBObject('_id', '$attributes.value'))
)

Using the extension, it would look more like this:

def output = ( AggregateBuilder.aggregate(collection)
        .match('_id.demoId', new ObjectId(demoId))
        .unwind('$attributes')
        .match('attributes.id', attributeId)
        .group('_id', '$attributes.value')
        .run()
)

Further converted examples are available on the Wiki.

Release Notes

  • 0.1.3 (Release TBD)
    • Throw exception is in GroupBuilder if targetField value already set #4
  • 0.1.2 (Released 1-4-2013)
    • Add DBO to assist in creating DBObjects in Java
    • Add DBL to assist in creating lists in Java
  • 0.1.1 (Released 9-4-2012)

    • Requires MongoDB Java driver 2.9.0+
    • Add AggregateBuilder.run() method using aggregate driver helper method
    • Fix "No target field for operand" error using GroupBuilder.start(...)
    • GroupOperators and PipelineOperators are now package-private
    • Add overloads to AggregateBuilder match and group methods to support common builders
  • 0.1.0 (Released 8-12-2012)

    • Initial release
    • Requires MongoDB Java driver 2.8.0+

Build Status

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.