How to use MongoDB with ColdFusion
<p>I am using MongoDB 3.2.3 and the mongo-java-driver-3.2.2.jar library.</p>

<p>I did the following in order to connect to the server and then to a specific database. I then create a collection named <code>col1</code>:</p>

<pre><code>&lt;cfset Mongo  = CreateObject("java","com.mongodb.MongoClient")&gt;
&lt;cfset Mongo.init("192.168.0.30")&gt;
&lt;cfset db = Mongo.getDatabase('testaj')&gt;
&lt;cfset db.createCollection("col1") &gt;
</code></pre>

<p>I got the following code from the internet in order to insert a document into the collection:</p>

<pre><code>&lt;cffunction name="m" returntype="any"&gt;
    &lt;cfargument name="value" type="any"&gt;
    &lt;cfif IsJSON(arguments.value)&gt;
        &lt;cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse(arguments.value)&gt;
    &lt;cfelse&gt;
        &lt;cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse( SerializeJSON(arguments.value) )&gt;     
    &lt;/cfif&gt;
    &lt;cfreturn local.retrun&gt;
&lt;/cffunction&gt;

&lt;cfset doc = {
    "Name"  = "Marc",
    "Spouse"= "Heather",
    "Fruit" = "Mango",
    "Kids"  = [
                {"Name"="Alexis", "Age"=7, "Hair"="blonde", "Description"="crazy" },
                {"Name"="Sidney", "Age"=2, "Hair"="dirty blonde", "Description"="ornery" }
            ],
    "Bike" = "Felt",
    "LoveSQL" = true,
    "TS" = now(),
    "Counter" = 1
    }&gt;
&lt;cfset doc = SerializeJSON(doc)&gt;
&lt;cfset doc = m(doc)&gt;

&lt;cfset col1.save(doc)&gt;
</code></pre>

<p>Unfortunately the last line generates the following error:</p>

<pre><code>No matching Method/Function for com.mongodb.MongoCollectionImpl.save(com.mongodb.BasicDBObject) found
</code></pre>

<p>It seems to be completely logical because when I output (via a <code>cfdump</code>) the content of the class <code>com.mongodb.MongoCollectionImpl</code>, I don't see the method <code>save</code>.</p>

<p>Does anyone know how to insert a MongoDB document in ColdFusion using this Java driver?<br>
Should I import another library or class?</p>