Skip to content

1. Installation & Configuration

Cavan Vannice edited this page Mar 6, 2024 · 3 revisions

Installation & Configuration

  1. Install MongoDB and start up an instance of mongod or sign up for a free account with a third party DB service like MongoLab
  2. Create a Coldbox application ( box install coldbox && box coldbox create app ) or use an existing one
  3. With CommmandBox just type box install cbmongodb from the root of your project.
  4. Add your settings (with your own config) to config/Coldbox.cfc

Localhost Example Without Authentication

MongoDB = {
	//an array of servers to connect to
	hosts= [
	{
		serverName='127.0.0.1',
		serverPort='27017'
	}
  ],
  	//The default database to connect to
	db 	= "mydbname",
	//whether to permit viewing of the API documentation
	permitDocs = true,
	//whether to permit unit tests to run
	permitTests = true,
	//whether to permit API access to the Generic API (future implementation)
	permitAPI = true
};

See Advanced Connections for configuration options using authentication, clustering and additional options.

  1. Extend your models to use cbmongodb.models.ActiveEntity (or cbmongodb.models.GEOEntity), add your collection component attribute and, optionally, a database attribute - if not specified, the database from your configuration will be used
In your component attributes, you will also need to specify the collection to be used. For those coming from relational databases, for our purposes, a collection is equivalent to a table.

Now all of our operations will be performed on the "peoplecollection" collection (which will be created if it doesn't exist).

component name="MyDocumentModel" extends="cbmongodb.models.ActiveEntity" collection="peoplecollection" database="MyNewDatabase" accessors=true{

}