Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tweak

  • Loading branch information...
commit b20c988cb21fb61d651af0491cc7f9829c090242 1 parent ee7ab4c
unknown authored
View
9 part2/ExpressionBuilderTest.cfc
@@ -8,9 +8,10 @@
function $testFluentChain(){
+ name_list = ['bill_1','bill_202','bill_101','bill_999','bogus_bill','bill_506'] ;
criteria = builder.start().
inArray( 'TAGS', 'Java' ).
- $nin( 'AUTHOR', ['bill_1','bill_202','bill_101','bill_999','bogus_bill','bill_506'] ).
+ $nin( 'AUTHOR', name_list ).
exists('BODY' , 'orci').
get();
@@ -52,7 +53,8 @@ function $testInArray(){
function testNIN(){
builder.start();
- temp = builder.$nin( 'AUTHOR', ['bill_1','bill_202','bill_101','bill_999','bogus_bill'] );
+ names = ['bill_1','bill_202','bill_101','bill_999','bogus_bill'];
+ temp = builder.$nin( 'AUTHOR', names );
q = createObject('java', 'com.mongodb.BasicDBObject').init(builder.get());
debug(q);
items = coll.find(q,keys);
@@ -92,7 +94,8 @@ function testInWithStringList(){
function testIn(){
builder.start();
- temp = builder.$in( 'AUTHOR', ['bill_1','bill_202','bill_101','bill_999','bogus_bill'] );
+ names = ['bill_1','bill_202','bill_101','bill_999','bogus_bill'];
+ temp = builder.$in( 'AUTHOR', names );
q = createObject('java', 'com.mongodb.BasicDBObject').init(builder.get());
debug(q);
items = coll.find(q,keys);
View
31 part2/MongoDB.cfc
@@ -12,6 +12,37 @@ mongo = createObject('java', 'com.mongodb.Mongo').init( variables.server_name ,
db = mongo.getDb(db_name);
collection = db.getCollection(collection_name);
+ /*---------------------------------------------------------------------
+
+ DSL for MongoDB searches:
+
+ mongo.expressionBuilder().
+
+ results = mongo.startsWith('name','foo'). //string
+ endsWith('title','bar'). //string
+ exists('field','value'). //string
+ regex('field','value'). //string
+ eq('field','value'). //numeric
+ lt('field','value'). //numeric
+ gt('field','value'). //numeric
+ gte('field','value'). //numeric
+ lte('field','value'). //numeric
+ in('field','value'). //array
+ nin('field','value'). //array
+ mod('field','value'). //numeric
+ size('field','value'). //numeric
+ search('title,author,date', limit, start);
+
+ search(keys=[keys_to_return],limit=num,start=num);
+
+
+
+
+-------------------------------------------------------------------------------------*/
+
+builder = createObject('component','ExpressionBuilder');
+
+
function getMongo(){
return mongo;
}
View
13 part2/MongoDBTest.cfc
@@ -72,7 +72,7 @@
- function $exploreStringSearchExpression(){
+ function $exploreStringSearchExpression2(){
coll = mongo.getCollection('blog');
key_exp = {TITLE=1,TS=1,AUTHOR=1};
@@ -94,7 +94,7 @@
}
- function $buildSearchExpressionWithBuilder(){
+ function $buildSearchExpressionWithBuilder2(){
coll = mongo.getCollection('blog');
// BasicDBObjectBuilder.start().add( "name" , "eliot" ).add( "number" , 17 ).get()
@@ -116,7 +116,7 @@
}
- function $findByExpression(){
+ function $findByExpression2(){
coll = mongo.getCollection('blog');
key_exp = {TITLE=1,TS=1};
@@ -160,7 +160,7 @@
function genDataTest(){
- //genBlogData() ;
+ // genBlogData() ;
}
@@ -184,14 +184,15 @@
var max = arrayLen(tags);
var shuffled = createObject('java','java.util.ArrayList').init(tags);
var r1 = randrange(1,max);
- var r2 = randrange(r1,max)
+ var r2 = randrange(r1,max);
var newTags = [];
+
//Note case sensitivity!!
mongo.getCollection('blog');
for(i; i < 1000;i++){
createObject('java','java.util.Collections').shuffle(tags);
r1 = randrange(1,max);
- r2 = randrange(r1,max)
+ r2 = randrange(r1,max);
newTags = shuffled.subList(r1,r2);
//createObject('java','java.util.Collections').shuffle(newTags);
Please sign in to comment.
Something went wrong with that request. Please try again.