dbs-and-docs-test-bulkAddDriver

node v4.9.1
version: 28.0.0
endpointsharetweet
module.exports = bulkAddDriverTest; function findProblemRecords(record) { return record.ok === false; } //b: { ok: true, index: 2, id: "3", db: db } function bulkAddDriverTest(a, b) { return function(err, res) { // what a and b are without having to have a global var ProblemRecords = res.find(findProblemRecords); if (err === a && ProblemRecords !== undefined) { console.log('Problem! At least one of your documents didn\'t save.: '); console.log(JSON.stringify(res)); } else if (err === a && ProblemRecords === undefined) { b.db.allDocs({ include_docs: true, attachments: false, keys: res.id }, function(err, result_alldocs) { if (err) { return console.log(err); } // handle result if (result_alldocs) { var missingitems = []; if (result_alldocs.rows[b.index].doc.hasOwnProperty('firstName') !== true) { missingitems.push('firstName'); } if (result_alldocs.rows[b.index].doc.hasOwnProperty('suspended') !== true) { missingitems.push('suspended'); } if (result_alldocs.rows[b.index].doc.hasOwnProperty('violations') !== true) { missingitems.push('violations'); } if (result_alldocs.rows[b.index].doc.hasOwnProperty('plates') !== true) { missingitems.push('plates'); } if (missingitems.length > 0) { console.log('Problem! One of your docs is missing the following information: ' + JSON.stringify(missingitems)); } else { console.log('Success! Done.'); console.log('response: ' + JSON.stringify(res)); } } }); } else { console.log('There was an error: ' + JSON.stringify(err)); } }; }
Loading…

no comments

    sign in to comment