Logical $or operator

71 views
Skip to first unread message

Proxen

unread,
Feb 28, 2013, 1:13:15 PM2/28/13
to cfmo...@googlegroups.com
Hi! I'm quite new to ColdFusion and new in MongoDB too, so I would really appreciate a bit of help.

In first place, I have to thank you for the development of this fantastic library. I don't know what I would have done without it.

I have to make a query using the logical $or operator. I have managed to have it working on the mongo shell, however, I couldn't move it to CFMongoDB. This is the original query I had running in SQL Server:
SELECT * FROM history WHERE (userid = 1 OR ip = '127.0.0.1') AND date < GETDATE()
And this is the query that I managed to have working on my mongo shell:
db.history.find({$or : [{'USERID':1}, {'IP':'127.0.0.1'}], 'DATE':{$lt:new Date()}})

The problem is that I am being unable to have this previous query running with CFMongoDB. Here is my attempt:
application.mongo.getDBCollection('history').query()
.$or([{'USERID':1}, {'IP':'127.0.0.1'}])
.$lt({'DATE':Now()})
.find().asArray();

And this is the error that I'm getting:
The method $or was not found in component /Applications/ColdFusion10/cfusion/wwwroot/inc/cfmongodb/core/SearchBuilder.cfc.

Any idea of why is this not working?

Chris Blackwell

unread,
Feb 28, 2013, 5:52:53 PM2/28/13
to cfmo...@googlegroups.com
The error message is pretty clear about the reason; SearchBuilder doesn't have an $or() method.
However, you can write your query using DBCollection.find() method directly

application.mongo.getDBCollection('history').find({
  "$or" : [
     {"USERID": 1}, 
     {"IP": "127.0.0.1"}
  ], 
  'DATE':{"$lt": now()}
});

This is basically the same query you were running in the shell, just using cf's now() function for the current timestamp.

Chris

--
You received this message because you are subscribed to the Google Groups "CFMongoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfmongodb+...@googlegroups.com.
To post to this group, send email to cfmo...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfmongodb?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Proxen

unread,
Feb 28, 2013, 7:03:55 PM2/28/13
to cfmo...@googlegroups.com
It's running fantastically, just what I was looking for. I didn't know that I could put things inside the find() too. Thank you very much, Chris.
Reply all
Reply to author
Forward
0 new messages