CFMongoDBMongoDBColdFusion 开发包,示例代码:

<cfscript>

//save
col = mongo.getDBCollection( &#39;my_collection&#39; );
my_struct = {
  name = &#39;Orc #getTickCount()#&#39;
  foo = &#39;bar&#39;
  bar = 123
  &#39;tags&#39;=[ &#39;cool&#39;, &#39;distributed&#39;, &#39;fast&#39; ]
};

col.save( my_struct );

//query
result = col.query().startsWith(&#39;name&#39;,&#39;Orc&#39;).find(limit=20);
writeOutput(&quot;Found #result.size()# of #result.totalCount()# Orcs&quot;);

//use the native mongo cursor. it is case sensitive!
cursor = result.asCursor();
while( cursor.hasNext() ){
  thisOrc = cursor.next();
  writeOutput(&quot; name = #thisOrc[&#39;name&#39;]# 
&quot;);
}

//use a ColdFusion array of structs. this is not case sensitive
orcs = result.asArray();
for(orc in orcs){
  writeOutput(&quot; name = #orc.name# 
&quot;);
}

</cfscript>

 


Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务