You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Randy Merrill edited this page Jan 5, 2012
·
1 revision
Mongo4CF is designed to be used as an application singleton. When you create the Mongo object you establish the connection to the MongoDB server and the Java driver controls the connection pool. When your application is finished, close the connections to the MongoDB server.
Usage
Here is an example of creating a singleton in Application.cfc:
component {
public boolean function onApplicationStart() {
// Connect to the MongoDB server
application.mongo = createObject('component', 'mongo4cf.mongo').init();
}
public void function onApplicationEnd(required struct applicationScope) {
// Close the MongoDB connections
arguments.applicationScope.mongo.close();
}
}
Once you have your mongo singleton you can connect to a database, select a collection, insert a new record, and find the record again: