Creates, registers, and administers Verity search engine
 collections.
 A collection that is created with the cfcollection tag is
 internal. A collection created any other way is external.
 A collection that is registered with CFML using the
 cfcollection tag or registered with the K2 Server by editing
 the k2server.ini file is registered. Other collections are
 unregistered.
					
						  
					
					<cfcollection action="categorylist">
					
				
							  cfcollection(action="categorylist");
						
listcategorylistcreatedeleteoptimizelistmaprepairenglishfalsetruefalseverityveritysolrIn this example we demonstrate using the cfcollection function to build a function which first checks if a collection already exists (and has records), and if not, creates the collection.
public boolean function createCollection( required string collectionName ) {
	// var scope a variable to check if the collection already exists
	var collectionExists = '';
	// use cfcollection to get a list of documents from the passed in collection
	cfcollection( action = 'list', collection = arguments.collectionName, name = 'collectionExists' );
	// see if the collection has any records
	if( !collectionExists.recordCount ) {
		// it does not, but wrap create in a try in case it exists but is merely empty
		try {
			// use cfcollection to create a new collection
			cfcollection( action = 'create', collection = arguments.collectionName );
		// catch if this collection already exists
		} catch (any e) {
			// it does, return false
			return false;
		}
	// otherwise
	} else {
		// collection already has records (and thus exists), return false
		return false;
	}
	// the collection was successfully created, return true
	return true;
}Expected Result: True, if the collection was created; False, if the collection already exists
In this example we demonstrate using the <cfcollection> tag to build a function which first checks if a collection already exists (and has records), and if not, creates the collection.
<cffunction access="public" returntype="boolean" name="createCollection">
	<cfargument name="collectionName" type="string" required="true" />
	<!--- var scope a variable to check if the collection already exists --->
	<cfset var collectionExists = ""; />
	<!--- use cfcollection to get a list of documents from the passed in collection --->
	<cfcollection action="list" collection="#arguments.collectionName#" name="collectionExists" />
	<!--- see if the collection has any records --->
	<cfif NOT collectionExists.recordCount>
		<!--- it doesn't, but wrap create in a try in case it exists but is merely empty --->
		<cftry>
			<!--- use cfcollection to create a new collection --->
			<cfcollection action="create" collection="#arguments.collectionName#" />
		<!--- catch if this collection already exists --->
		<cfcatch type="any">
			<!--- it does, return false --->
			<cfreturn false />
		</cfcatch>
		</cftry>
	<!--- otherwise --->
	<cfelse>
		<!--- collection already has records (and thus exists), return false --->
		<cfreturn false />
	</cfif>
	<!--- the collection was successfully created, return true --->
	<cfreturn true />
</cffunction>Expected Result: True, if the collection was created; False, if the collection already exists
Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.