cbops
Version:
Cosmos DB Bulk Operations CLI, that can load objects from JSON files and create or upsert them, or delete items from Container, based on provided query.
24 lines (20 loc) • 547 B
JavaScript
const fs = require('fs');
//function to only load the file and parse it to JSON to validate it.
//it returns the array of js objects
function loadFile(fullFileName) {
try {
// Load external JSON
const jsonData = fs.readFileSync(fullFileName, {
encoding: 'utf8',
});
// Parse the JSON into an array of documents
const documents = JSON.parse(jsonData);
return { documents, error: null };
} catch (error) {
// console.error(error);
return { documents: [], error };
}
}
module.exports = {
loadFile,
};