MongoDB Aggregate Query

Source: Internet
Author: User
Tags mongodb aggregate
Java code www.2cto. commongoclient?clientnull; try {mongoclientnew?client (102.198.119.29, 27017); dbdb=client. getDB (syslog); set the Where condition Scheme ($ match, newBasicDBOb

Java code www.2cto.com using client = null for MongoDB aggregation query; try {using client = new using client (102.198.119.29, 27017); DB db = using client. getDB (syslog); // set the Where condition DBObject match = new BasicDBObject ($ match, new BasicDBOb

MongoDB Aggregate Query

Java code www.2cto.com

Publish client publish client = null;

Try {

Publish client = new publish client ("102.198.119.29", 27017 );

DB db = logging client. getDB ("syslog ");

// Set the Where Condition

DBObject match = new BasicDBObject ("$ match", new BasicDBObject (

"DATE ",

(New BasicDBObject ("$ gt", "00:19:00"). append (

"$ Lt", "09:19:00 ")));

// Set the grouping Field

BasicDBObject groupFilters = new BasicDBObject ("_ id", "$ PRIORITY ");

// Count the number of rows for the grouping Field

GroupFilters. put ("count", new BasicDBObject ("$ sum", 1 ));

BasicDBObject group = new BasicDBObject ("$ group", groupFilters );

// Set the set of displayed Fields

DBObject fields = new BasicDBObject ("PRIORITY", 1 );

Fields. put ("_ id", "$ PRIORITY ");

DBObject project = new BasicDBObject ("$ project", fields );

AggregationOutput output = db. getCollection ("messages"). aggregate (

Match, project, group );

System. out. println (output. getCommandResult ());

} Catch (UnknownHostException e ){

E. printStackTrace ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.