I am trying to iterate through an array and push the contents from the array to another array if they satisfy some basic condition. Really simple stuff. PLease help me.
Getting list of DBs in MongoDB
>>var dbs = db.getMongo().getDBNames();
>>dbs
[ "admin", "newdb", "newdb2", "local", "test" ]
Get array length:
var arrayLength = dbs.length;
Creating an empty array
var databases = []
Pushing to the databases array content from dbs array if content is not equal to 'admin','local' or 'test'
for (var i = 0 ; i < arrayLength; i++) {
if (!(dbs[i] == "admin") || !(dbs[i] == "local") || !(dbs[i] == "test")) {
databases.push(dbs[i]);
}
}
Expecting only "newdb" and "newdb2" to be in the databases array. But everything is being pushed
>databases
[ "admin", "newdb", "newdb2", "local", "test" ]
What's going on here? Only newdb and newdb2 needs to be in the "databases" array.
if(dbs[i] != "admin" && dbs[i] != "local" && dbs[i] != "test").