List of usage examples for com.mongodb GroupCommand toDBObject
public DBObject toDBObject()
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
public void group(final ButtonBase button) { final DBCollection col = getCollectionNode().getCollection(); DBObject keys = ((DocBuilderField) getBoundUnit(Item.grpKeys)).getDBObject(); DBObject initial = ((DocBuilderField) getBoundUnit(Item.grpInitialValue)).getDBObject(); DBObject query = ((DocBuilderField) getBoundUnit(Item.grpQuery)).getDBObject(); String reduce = getStringFieldValue(Item.grpReduce); String finalize = getStringFieldValue(Item.grpFinalize); final GroupCommand cmd = new GroupCommand(col, keys, query, initial, reduce, finalize); // new DocView(null, "Group", col.getDB(), cmd.toDBObject()).addToTabbedDiv(); new DbJobCmd(col.getDB(), cmd.toDBObject(), null, button).addJob(); }
From source file:org.exist.mongodb.xquery.mongodb.collection.Group.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/* w ww.j a va 2 s. co m*/ // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String collection = args[2].itemAt(0).getStringValue(); BasicDBObject key = (BasicDBObject) JSON.parse(args[3].itemAt(0).getStringValue()); BasicDBObject condition = (BasicDBObject) JSON.parse(args[4].itemAt(0).getStringValue()); BasicDBObject initial = (BasicDBObject) JSON.parse(args[5].itemAt(0).getStringValue()); String reduce = args[6].itemAt(0).getStringValue(); // The finalize can be null String finalize = (args.length >= 8) ? args[7].itemAt(0).getStringValue() : null; // Get database DB db = client.getDB(dbname); DBCollection dbcol = db.getCollection(collection); // Propare groupcommand GroupCommand command = new GroupCommand(dbcol, key, condition, initial, reduce, finalize); System.out.println(command.toDBObject().toString()); if (LOG.isDebugEnabled()) { LOG.debug(command.toDBObject().toString()); } // Execute, finalize can have value null DBObject result = dbcol.group(command); // Execute query Sequence retVal = new StringValue(result.toString()); return retVal; } catch (JSONParseException ex) { LOG.error(ex.getMessage()); throw new XPathException(this, MongodbModule.MONG0004, ex.getMessage()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0003, ex.getMessage()); } }