1
0
mirror of /repos/Prototyper.git synced 2026-02-27 16:12:00 +01:00

added ensureContent for importer

This commit is contained in:
Aiko Mastboom
2013-04-20 17:59:42 +02:00
parent 96f2c2cb46
commit 0d5f29cbb7

View File

@@ -16,6 +16,9 @@ module.exports = function (config) {
config.errors && console.log('ERR2 getMongoContent', err);
return callback(err);
}
if (!options.query){
return callback(new Error('Data not found ' + options.collection + '/ missing query'));
}
if (options.query._id && !(options.query._id instanceof Object)) {
try {
options.query._id = new ObjectID.createFromHexString(options.query._id);
@@ -38,6 +41,28 @@ module.exports = function (config) {
});
}
function ensureContent(options, callback) {
if (!options.query){
options.query = {
name: options.name
}
}
getMongoContent(options, function (err, result) {
if(err) {
if (/Data not found*/.test(err.message)) {
setMongoContent({name:options.name},options, function (err, result) {
if(err) {
return callback(err);
}
return callback(null,result);
})
} else {
return callback(err);
}
}
return callback(null,result);
})
}
function getMongoAttribute(options, callback) {
config.debug && console.log('getMongoAttribute options', options);
return getMongoContent(options, function (err, result) {
@@ -217,7 +242,8 @@ module.exports = function (config) {
getMongoAttribute: getMongoAttribute,
getMongoContent: getMongoContent,
setMongoAttribute: setMongoAttribute,
setMongoContent: setMongoContent
setMongoContent: setMongoContent,
ensureContent: ensureContent
};
};