Shared State in (map-reduce) function

41 views
Skip to first unread message

Timothy Washington

unread,
Apr 1, 2012, 9:54:49 PM4/1/12
to congomongo-dev
Hi there, 

I have a web client that's making simultaneous ajax calls to get a list of accounts and entries. When the (get-accounts) or (get-entries) calls are made individually, the correct results are returned 100% of the time. But When they are called simultaneously, the congo mongo driver mixes the results. So in (get-accounts) and (get-entries), congomongo will both return the same list of accounts. I'm using a webnoir front-end facade to congomongo calls, which use map-reduce to get the Accounts and Entries.

This is the Clojure map-reduce codeThis is the mongodb JSON structure it's traversing. I have to assume that the (map-reduce) calls are mixing the results (ie, there's shared state somewhere in that function). Is there a way to avoid this problem? Am I using the function correctly? I'm using [congomongo "0.1.8"]. Thanks in advance. 


Tim Washington 


Sean Corfield

unread,
Apr 2, 2012, 1:34:52 AM4/2/12
to congomo...@googlegroups.com
I believe the problem is you're using the same collection for both
results so one is overwriting the other when you run both queries
together. Since you want to return the results, instead of
:result-collection, specify {:inline 1}

Take a look at the out parameter documentation for map-reduce, as well as:

http://api.mongodb.org/java/current/com/mongodb/MapReduceCommand.html

Sean

Timothy Washington

unread,
Apr 2, 2012, 11:08:23 AM4/2/12
to congomo...@googlegroups.com
Ahh, that did the trick. I knew I was using those arguments incorrectly. I dug down in the source to see that parameter: 
Reply all
Reply to author
Forward
0 new messages