MongoDB notes

Executing a MongoDB query from command line

mongo -u 'MyUsername' -p 'MyPassword' --eval 'db.getCollection("fs.files").find({"_id": ObjectId("fffffffff")});' '127.0.0.1:27017/MyDBName' 

MongoDB Notes

When using MongoDB to store files, we have 2 collections:
1. The place where MongoDB store the file metadata: store.files
2. Ans place where MongoDB store the file content: store.chunks

Depending on the size of the file, one entry in store.files can points to many entries in store.chunks. The bigger the file, the more entry you’ll encounter.


// Show all/ list all entries from store.files
db.getCollection('store.files').find({});

// Show only a particular entry from store.files
db.getCollection('store.files').find({ _id : ObjectId("5b02d232cbce1d07e08401c7")});

// The same can be used for store chunks.
db.getCollection('store.chunks').find({});

The metadata/fields in the store.files can be expanded during query runtime (not saved into the MongoDB, only displayed during runtime)

db.getCollection('store.files').aggregate([
{ $match: { _id : ObjectId("5b02d232cbce1d07e08401c7")} },
{ $addFields:{'key_reference':'1234'}}
]);

Or we do an update into store.files which will be saved into the MongoDB

db.getCollection('store.files').updateMany({ _id : ObjectId("5b02d232cbce1d07e08401c7")},{$set:{'key_reference':'1234'}});

CentOS 6 repo Settings

To fix repo settings in CentOS 6

1. make sure there is no proxy or funny settings in
vi /etc/yum.conf

2. There are a couple of files within /etc/yum.repos.d/. Make sure the url are correct (accessible) and enabled=1
ll /etc/yum.repos.d/

3. Cleanup the repo, list and retest
yum –enablerepo=base clean metadata;
yum repolist all
yum search java-1.8.0-openjdk

Setting log4j log level programmatically


private static void setupLog4j() {
System.out.println("setupLog4j");
BasicConfigurator.resetConfiguration();
// Start clean.
Logger.getRootLogger().removeAllAppenders();
// Create appender
ConsoleAppender console = new ConsoleAppender();
// Configure the appender
String PATTERN = "%d --[ %p ] %l: %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.activateOptions();
console.setName("stdout");
Logger.getRootLogger().setLevel(Level.DEBUG);
BasicConfigurator.configure(console);
LOG = Logger.getLogger(MinerTest.class);
}

Knowing you exception class name

To know what is your exception class name, in case you want to have a more specific catch.

} catch (Exception e){
LOG.error("SQL error when processing " + requestId+". Exception class:"+ e.getClass().getCanonicalName());
throw(e);
}

RedHat / Centos Firewall

To add an exception to firewall
In RedHat/CentOS 6

iptables --line -vnL
iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.0.0/16 -j ACCEPT
iptables -D INPUT -p tcp -s 192.168.0.0/16 -j ACCEPT
service iptables save

In RedHat/CentOS 7

firewall-cmd --list-all
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-source=192.168.0.0/16
firewall-cmd --permanent --zone=public --remove-source=192.168.0.0/16
firewall-cmd --reload
systemctl disable firewalld