Created
August 15, 2013 18:57
-
-
Save Albert-IV/6243682 to your computer and use it in GitHub Desktop.
Example for changing logic depending on mongo results.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CollectionOne.find( { 'search-term-here' : 'value' }, function(e, col1) { | |
if (e) return cb(e); | |
CollectionTwo.find( { 'your-search-here' : 'value' }, function(e, col2) { | |
if (e) return cb(e); | |
if (!results || !results.length) { | |
noPreviousResults(col1, cb); | |
} else { | |
previousResults(col1, col2, cb); | |
} | |
}); | |
}); | |
var noPreviousResults = function(col1, cb) { | |
var newCollection = {}; // New record | |
newCollection = new CollectionTwo(newCollection); | |
newCollection.save(function(e) { | |
if (e) return cb(e); | |
col1.property = 'Some Arbitrary Value' | |
col1.save(cb); | |
}) | |
}; | |
var previousResults = function(col1, col2, cb) { | |
col2.someProperty = 'something'; | |
col1.someOtherProperty = 'something-else'; | |
col2.save(); | |
col1.save(cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment