[nodejs] Re: parallel findOrCreate functions with mongoose

2012-07-29 Thread Jaime Morales
mlegenhausen, I tried this and it didn't seem to work correctly. But then I found your workaround . This code is working now: // in my schema definition: AccountSchema.statics.findAndModify = function (query, sort, doc, options, callback) {

[nodejs] Re: parallel findOrCreate functions with mongoose

2012-07-29 Thread Jaime Morales
Roly, Thanks. I will look into this solution if I can't get findAndModify to work. On Saturday, July 28, 2012 8:44:23 PM UTC-7, Roly Fentanes wrote: > > One solution could be to keep a hash of query objects. Every time before > you run a query for find, identify the query with something like >

[nodejs] Re: parallel findOrCreate functions with mongoose

2012-07-29 Thread mlegenhausen
Why you do not use the findAndModify method? This method can create an document when it is not find via the upsert: true parameter. This method has the advantage to be atomic like a transaction and you get no problems when you run multiple node process which execute your findOrCreate method. Am

[nodejs] Re: parallel findOrCreate functions with mongoose

2012-07-28 Thread Roly Fentanes
One solution could be to keep a hash of query objects. Every time before you run a query for find, identify the query with something like JSON.stringify() then check if the hash includes that query already. If it doesn't, create an array equal to that query id with the callback as the only elem