Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
db.collection(req.params.collection, function(err, collection) {
if (err) {
return res.json({'error': err.toString() });
}
else {
var respCallback = function(json) {
// Convert JSON object to MongoDB-Extended JSON
var e = EJSON.stringify(json);
var j = JSON.parse(e);
return res.json(j);
};
//console.log(JSON.stringify(query));
// Convert query to MongoDB Extended JSON
var j = JSON.stringify(query);
var q = EJSON.parse(j);
// console.log(j,q);
return callback && callback(collection, q, respCallback);
}
});
}
// Check for existance of connection
if(connection_list[req.params.conn] === undefined){
res.status(400).json({'msg': req.i18n.__('Invalid connection name')});
}
// Validate database name
if(req.params.db.indexOf(' ') > -1){
res.status(400).json({'msg': req.i18n.__('Invalid database name')});
}
// Get DB's form pool
var mongo_db = connection_list[req.params.conn].native.db(req.params.db);
try{
var eJsonData = ejson.parse(req.body.objectData);
}catch(e){
console.error('Syntax error: ' + e);
res.status(400).json({'msg': req.i18n.__('Syntax error. Please check the syntax')});
return;
}
mongo_db.collection(req.params.coll).save(eJsonData, function (err, doc, lastErrorObject){
if(err){
console.error('Error updating document: ' + err);
res.status(400).json({'msg': req.i18n.__('Error updating document') + ': ' + err});
}else{
if(doc['nModified'] === 0){
console.error('Error updating document: Document ID is incorrect');
res.status(400).json({'msg': req.i18n.__('Error updating document: Syntax error')});
}else{
res.status(200).json({'msg': req.i18n.__('Document successfully updated')});
gateway.parseMessage = function(message) {
// Attempt to parse the message.
try { message = EJSON.parse(message.toString()); }
catch(e) { return null; }
// The message has to be something.
if(!message) {
return null;
}
return message;
};
return new Promise((resolve, reject) => {
const protFile = msID + ExpImpFilesDocuments.FILENAME_POSTFIX;
let AllProtocolsDoc = undefined;
try {
AllProtocolsDoc = EJSON.parse(fs.readFileSync(protFile, 'utf8'));
if (!AllProtocolsDoc) {
return reject('Could not read documents file '+protFile);
}
} catch (e) {
return reject('Could not read documents file '+protFile+'\n'+e);
}
// Replace old user IDs with new users IDs
let protcolsIDs = [];
for(let p=0; p
.then(doc => {
if (doc) {
return reject ('Meeting series with ID: '+ msID+' already exists. Cannot import.');
} else {
const msFile = msID + ExpImpMeetingSeries.FILENAME_POSTFIX;
let msDoc = undefined;
try {
msDoc = EJSON.parse(fs.readFileSync(msFile, 'utf8'));
if (!msDoc) {
return reject('Could not read meeting series file '+msFile);
}
} catch (e) {
return reject('Could not read meeting series file '+msFile);
}
// Replace old user IDs with new users IDs
for (let i=0; i
return new Promise((resolve, reject) => {
const usrFile = msID + ExpImpUsers.FILENAME_POSTFIX;
let allUsersDoc = undefined;
try {
allUsersDoc = EJSON.parse(fs.readFileSync(usrFile, 'utf8'));
if (!allUsersDoc) {
return reject('Could not read user file '+usrFile);
}
} catch (e) {
return reject('Could not read user file '+usrFile+'\n'+e);
}
// We have some sequential DB inserts/updates from two cases now.
// We chain them in a Promise chain.
let promiseChain = [];
for(let u=0; u target DB!
allUsersDoc[u].roles = {msID: roleValueForMS}; // Kill all other roles, just keep the one for this MS
promiseChain.push(
db.collection('users')
page = parseInt(req.params.page);
}
var skip = 0;
if(page > 1){
skip = (page - 1) * page_size;
}
var limit = page_size;
var query_obj = {};
var validQuery = true;
var queryMessage = '';
if(req.body.query){
try{
query_obj = ejson.parse(req.body.query);
}catch(e){
validQuery = false;
queryMessage = e.toString();
query_obj = {};
}
}
mongo_db.collection(req.params.coll).find(query_obj, {skip: skip, limit: limit}).toArray(function (err, result){
if(err){
console.error(err);
res.status(500).json(err);
}else{
mongo_db.collection(req.params.coll).find({}, {
skip: skip,
limit: limit
}).toArray(function (err, simpleSearchFields){
.then(doc => {
if (doc) {
console.log("DB Schema Version: "+doc.version);
const schemaFile = msID + ExpImpSchema.FILENAME_POSTFIX;
let exportedSchema = undefined;
try {
exportedSchema = EJSON.parse(fs.readFileSync(schemaFile, 'utf8'));
if (!exportedSchema) {
return reject("Could not read schema file "+schemaFile);
}
} catch (e) {
return reject("Could not read schema file "+schemaFile);
}
if (ExpImpSchema.MADE_FOR_SCHEMA !== doc.version
|| ExpImpSchema.MADE_FOR_SCHEMA !== exportedSchema.version
|| doc.version !== exportedSchema.version) {
console.log("*** WARNING *** Schema mismatch!");
console.log(" This importer is made for database schema version: "+ExpImpSchema.MADE_FOR_SCHEMA);
console.log(" Your database has schema version : "+doc.version);
console.log(" Your exported data has schema version : "+exportedSchema.version);
console.log(" Alyways migrate to the most recent DB schema before export/import!");
console.log(" Alyways use matching exporter!");
.collection(collection.name)
.listIndexes()
.toArray();
for(index of indexes) {
if(index.name !== '_id_') {
spec.databases[dbName].collections[collection.name].indexes[index.name] = {
keys: index.key,
options: _.omit(index, ['key','v','name','ns']),
dropFirst: false
}
}
}
if(args.data !== 'no') {
let query = {};
if(args.query) {
query = EJSON.parse(args.query);
}
data = await db
.collection(collection.name)
.find(query)
.toArray();
for(d of data) {
fs.appendFileSync(path.join(repo, 'data', dbName, `${collection.name}.jsonl`), EJSON.stringify(d) + '\n');
}
}
}
if(Object.keys(spec.databases[dbName].collections).length === 0) {
delete spec.databases[dbName];
fs.rmdirSync(path.join(repo, 'data', dbName));
} else {
spec.databases[dbName].dropFirst = false;
}
var _ref7 = _asyncToGenerator(function* (data) {
try {
stream.pause();
const filterObj = {};
const dataObj = EJSON.parse(data.toString());
let dataDotNotatedObj = {};
dotNotate(dataObj, dataDotNotatedObj);
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = collectionSpec.upsertFields[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
let upsertField = _step5.value;
filterObj[upsertField] = dataDotNotatedObj[upsertField];
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {