Mais conteúdo relacionado Using Jaspersoft with MongoDB2. Session Overview
What is MongoDB?
Connecting to MongoDB from JasperServer
The MongoDB Query Language
Using MongoDB in iReport
Using Adhoc with MongoDB
©2010 Jaspersoft Corporation. Proprietary and Confidential 2
3. What is MongoDB
MongoDB (from "humongous") is an open source
document database written in C++.
MongoDB in a nutshell
Document-Oriented Storage (JSON Documents)
JSON-style documents with dynamic schemas offer simplicity and
power.
Full Index Support. Index on any attribute, just like you're used to.
Rich, document-based query language.
Map/Reduce
Flexible aggregation and data processing.
©2010 Jaspersoft Corporation. Proprietary and Confidential 3
4. The Jaspersoft MongoDB Query
Language
The Jaspersoft MongoDB Query Language is a JSON-
style declarative language for specifying what data to
retrieve from MongoDB. The connector converts this
query into the appropriate API calls and uses the
MongoDB Java connector to query the MongoDB
instance.
There are two types of queries supported:
API driven queries: These queries rely on the mongo-java-driver support
provided to query MongoDB.
Command driven queries: This queries allow the usage of MongoDB
Aggregation Framework operators
©2010 Jaspersoft Corporation. Proprietary and Confidential 4
5. Connecting Jaspersoft to MongoDB
Creating a JasperServer
Datasource
Setting connection URL
mongodb://<SERVER>:<PORT>/<COLLECTION>
and (optional) authentication
©2010 Jaspersoft Corporation. Proprietary and Confidential 5
6. API Driven Queries
Querying Mongo form Jasper
{
# The following parameter is mandatory.
collectionName : myCollection Details,
# The following parameters are optional
findQuery : { Details },
findFields : { Details },
sort : {Details},
mapReduce : {Details},
limit : int Details,
rowsToProcess : int Details
}
©2010 Jaspersoft Corporation. Proprietary and Confidential 6
7. Command Driven Queries
Querying mongo form Jasper
{
runCommand : { Command body },
# The following parameter is optional
rowsToProcess : int Details
}
Using runCommand to access the MongoDB aggregation framework
{
runCommand : {
aggregate : COLLECTION_NAME,
pipeline : [ List of aggregation operations ]
}
}
©2010 Jaspersoft Corporation. Proprietary and Confidential 7
8. Example Queries
Minimal
{ 'collectionName' : 'accounts’ }
Filtered and parameterized
{
'collectionName' : 'accounts',
'findQuery' : {
'status_date' : { '$gte' : $P{StartDate} },
'name' : { '$regex' : '^N', '$options' : '' }
}
}
©2010 Jaspersoft Corporation. Proprietary and Confidential 8
9. Example Queries
Specify the fields returned and sort the results
{
'collectionName' : 'accounts',
'findFields' : {
'name':1,
'phone_office':1,
'billing_address_city':1,
'billing_address_street':1,
'billing_address_country':1
},
'sort' : {
'billing_address_country':-1,
'billing_address_city':1
}
}
©2010 Jaspersoft Corporation. Proprietary and Confidential 9
10. Example Queries
Using the Aggregation
{
runCommand: {
aggregate : 'zips',
pipeline : [ { $group : { _id : '$state',
population: { $sum : '$pop'
}
}
},
{ $sort : { population : -1
}
}
]
}
©2010 Jaspersoft Corporation. Proprietary and Confidential 10
12. Additional Resources
MongoDB
http://www.mongodb.org/
MongoDB Documentation
http://docs.mongodb.org/manual/
The Jaspersoft MongoDB Query
Languagehttp://community.jaspersoft.com/wiki/jaspersoft-
mongodb-query-language
Right Outer Join Blog - by Matt Dahlman
http://mdahlman.wordpress.com/2011/09/02/simple-reporting-on-
mongodb/
JasperReports Server Documentation
http://community.jaspersoft.com/documentation/
©2010 Jaspersoft Corporation. Proprietary and Confidential 12