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')});
.then(allUsersDoc => {
if (allUsersDoc) {
// userIDsFlat may contain "free text" users that are not in DB
// We create a dict to look up which collected userIDs are really from DB
let userIDsFromDB = {};
allUsersDoc.map(usr => {
userIDsFromDB[usr._id] = 1;
});
const usrFile = msID + ExpImpUsers.FILENAME_POSTFIX;
fs.writeFileSync(usrFile, EJSON.stringify(allUsersDoc,null,2));
console.log('Saved: '+usrFile + ' with '+allUsersDoc.length+' users');
// Save mapping file old => new user ID
// But only with REAL DB users (skip free text users)
userIDsFlat.map(usrID => {
if (userIDsFromDB[usrID]) {
// default: newID === oldID
// This means, users are copied(!) from source DB to destination DB
// If newID is changed to an existing id from destination ID, this target user is used
let thisUser = ExpImpUsers.searchUser(allUsersDoc, usrID);
userIDsOuputMap[usrID] = {
'newID': usrID,
'hint': thisUser.username +" "+thisUser.profile.name
};
}
});
.then(allMinutesDoc => {
if (allMinutesDoc) {
const minFile = msID + ExpImpMinutes.FILENAME_POSTFIX;
fs.writeFileSync(minFile, EJSON.stringify(allMinutesDoc,null,2));
console.log('Saved: '+minFile + ' with '+allMinutesDoc.length+' minutes');
// Collect additional invited / informed users from older minutes
allMinutesDoc.map(min => {
min.visibleFor && min.visibleFor.map(userID => { // should be identical to meeting series
userIDs[userID] = 1;
});
min.informedUsers && min.informedUsers.map(userID => { // should be identical to meeting series
userIDs[userID] = 1;
});
min.participants && min.participants.map(part => { // might differ from meeting series users!
userIDs[part.userId] = 1;
});
min.topics && min.topics.map(top => { // iterate topics
top.responsibles && top.responsibles.map(resp => { // topic-responsibles
userIDs[resp] = 1;
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));
.wrap(100);
if (process.stdin.isTTY) {
// running in TTY mode, get template from non-positional argument
yargs
.usage('Usage: mgeneratejs [template]')
.demand(1, 'must provide a template file or string');
} else {
yargs.usage('Usage: mgeneratejs < [template]');
}
var argv = yargs.argv;
var template;
var stringifyStream = argv.jsonArray
? eJSONStringifyStream('[\n ', ',\n ', '\n]\n')
: eJSONStringifyStream('', '\n', '\n');
function generate() {
es.readable(function(count, callback) {
if (count >= argv.number) {
return this.emit('end');
}
this.emit('data', mgenerate(template));
callback();
})
.pipe(stringifyStream)
.pipe(process.stdout);
}
if (process.stdin.isTTY) {
var str = argv._[0];
template = _.startsWith(str, '{')
.strict()
.wrap(100);
if (process.stdin.isTTY) {
// running in TTY mode, get template from non-positional argument
yargs
.usage('Usage: mgeneratejs [template]')
.demand(1, 'must provide a template file or string');
} else {
yargs.usage('Usage: mgeneratejs < [template]');
}
var argv = yargs.argv;
var template;
var stringifyStream = argv.jsonArray
? eJSONStringifyStream('[\n ', ',\n ', '\n]\n')
: eJSONStringifyStream('', '\n', '\n');
function generate() {
es.readable(function(count, callback) {
if (count >= argv.number) {
return this.emit('end');
}
this.emit('data', mgenerate(template));
callback();
})
.pipe(stringifyStream)
.pipe(process.stdout);
}
if (process.stdin.isTTY) {
var str = argv._[0];
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