Skip to content

Instantly share code, notes, and snippets.

@CiscoKidxx
Last active August 29, 2015 14:27
Show Gist options
  • Save CiscoKidxx/18d41e924737a43693f6 to your computer and use it in GitHub Desktop.
Save CiscoKidxx/18d41e924737a43693f6 to your computer and use it in GitHub Desktop.
function mongoSqlCompare () {
function doSomething(aMongoUsers) {
return aMongoUsers;
}
// set empty array
var mongo_users = []
var xyz = []
// find all user objects in mongo db
stUser.find({}, function(err, res) {
if (err) throw err;
console.log('inside');
xyz = doSomething(mongo_users);
// jsonify the mongo db collections
var jsonString = JSON.stringify(res);
var jsonData = JSON.parse(jsonString);
// loop through each document and push GuiLoginName to array as a string
jsonData.forEach(function(element, i) {
mongo_users.push(jsonData[i].GuiLoginName);
})
});
console.log('outside');
console.log(xyz);
console.log(mongo_users);
// query sql database for all users
connection.query('SELECT * from users WHERE LDAPUser = 1', function(err, res) {
if (err) throw err;
// jsonify the response
var json_string = JSON.stringify(res);
var sqlUsers = JSON.parse(json_string);
// loop through each sql user object
sqlUsers.forEach(function(element, i) {
// Return true if the string in mongo_users matches the GuiLoginName value in the mongodb
var isMatch = mongo_users.some(function(match) {
return _.isMatch(sqlUsers[i], {GuiLoginName : match})
})
// if true
if (isMatch) {
console.log('Match!')
}
// if false, console.log the username who isn't in the sql databaase
else {
console.log(sqlUsers[i].GuiLoginName)
}
});
});
}
mongoSqlCompare();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment