Weird Scope Issue

13 views
Skip to first unread message

jarofclay

unread,
Nov 19, 2012, 9:04:45 PM11/19/12
to cfmo...@googlegroups.com
Cfmongodb is awesome.  It's working well in Wirebox as well.  We have this weird issue though when calling functions in a CFC that behaves differently than on a CFM page.  

Example (works in CFM):
coll  = mongoService.getDBCollection( "announcements" );
announcements =coll.query().$gt("expiredate", dateconvert("local2utc",now())).find( limit=1, sort={"ts"=-1} );

The same code above when in a CFC (assume mongoService is a injected configured mongo instance) doesn't work and it will throw an error:
coll is undefined.

This is where it gets really weird. If we do this.. it works. 
coll  = mongoService.getDBCollection( "announcements" );
coll; // or just a writedump(coll);
announcements =coll.query().$gt("expiredate", dateconvert("local2utc",now())).find( limit=1, sort={"ts"=-1} );

Scratches head.   We have tried this 20 different ways to Sunday (w/o Wirebox, instantiate from the function) and it behaves the same.  So Wirebox doesn't affect the result.  Any ideas on why this variable needs a touch? Is it lonely?? :)

Chris Blackwell

unread,
Nov 20, 2012, 6:55:58 AM11/20/12
to cfmo...@googlegroups.com
where are you executing the code in the cfc, i'm assuming its in a function?
so really you should scope the variables

have you tried

var coll = mongoService.getDBCollection( "announcements" );
var announcements = coll.query().$gt("expiredate", dateconvert("local2utc",now())).find( limit=1, sort={"ts"=-1} );




--
You received this message because you are subscribed to the Google Groups "CFMongoDB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfmongodb/-/KyTTc16zN_8J.
To post to this group, send email to cfmo...@googlegroups.com.
To unsubscribe from this group, send email to cfmongodb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfmongodb?hl=en.

Marc Esher

unread,
Nov 20, 2012, 7:32:16 AM11/20/12
to cfmo...@googlegroups.com
Hey Joe,

I confess, this is quite strange. First, what version of CF are you on? Have you tried restarting CF?

Now, some standard debugging:

What is "mongoService"?

What is different about it when it's used in your .cfm page vs. your component? Is it initialized differently? 

If you do this:
var coll = mongoService.getDBCollection( "announcements" );
coll.getMongoDBCollection();

does it error?

What if you do a simpler query: coll.findById(...);

All most likely shots in the dark but we need to start somewhere.

Marc


Marc Esher

unread,
Nov 20, 2012, 7:33:26 AM11/20/12
to cfmo...@googlegroups.com
And +1 to what Chris said: always var scope. Always. 

Though I don't think that's your issue here.
Reply all
Reply to author
Forward
0 new messages