Last active
August 29, 2015 14:09
-
-
Save jstrimpel/1d76b55b06494a5e7468 to your computer and use it in GitHub Desktop.
mongodb collection syncher example
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
// app/server/synchers/base.js | |
define(['lazoSyncher'], function (LazoSyncher) { | |
'use strict'; | |
// set up mongo connection here; not sure of best practices for establishing connections | |
// https://www.npmjs.org/package/mongodb | |
return LazoSyncer.extend({ | |
fetch: function (options) { | |
// get data from mongo | |
// pass the document name down; could come from parameters; doesn't really matter | |
var collection = db.collection(options.document); | |
collection.find({}).toArray(function (err, docs) { | |
if (err) { | |
return options.error(err); | |
} | |
// filter results | |
options.success(docs); | |
}); | |
} | |
}); | |
}); |
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
// models/model_name/server/syncher.js | |
define(['app/server/synchers/base'], function (BaseSyncher) { | |
'use strict'; | |
return BaseSyncher.extend({ | |
// override the base if needed | |
fetch: function (options) { | |
// syncher specific code, e.g. document name, set up filters | |
BaseSyncher.prototype.fetch.call(this, options); | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment