The env var $OPENSHIFT_MONGODB_DB_LOG_DIR points to the MongoDB log location.
Using bower for webapp package management: ui-date
Looking for a calendar widget to use with my AngularJS app, I found this one. This is also the first library I’ve come across where I’ve needed to use bower to install it for me. I’ve seen and used bower as part of the AngularJS tutorial, but this is my first experience using it out of necessity.
I already have node.js installed for the AngularJS tutorial, so installed bower globally using:
sudo npm install -g bower
and then installed the angular-ui date picker with:
bower install angular-ui-date --save
Following the rest of the steps to include the dependent js and css files, add the ui-date directive to an input field… and that was easy, now I have a jQuery UI date picker!
MongoDB usage notes (2)
Continuing prior notes from here.
Drop a database:
use databasename db.dropDatabase()
List distinct property values across all docs:
db.collectionname.distict("propertyname")
Remove docs in a collection – param is a doc query. If empty doc, removes all docs:
db.collectionname.remove({})
Date range query using $gt and $lt for a range:
db.collectionname.find({ "timestamp" : { "$gte" : ISODate("2014-07-08T19:50"), "$lt" : ISODate("2014-07-08T19:52") } })
[in progress]
MongoDB Java Driver notes
A few notes on using the MongoDB Java Driver API:
Getting a connection:
MongoClient client = new MongoClient("localhost", 27017); DB db = client.getDB("test");
Get a collection from connected db:
DBCollection collection = db.getCollection("example");
Find all docs in collection and iterate through results:
DBCursor c = collection.find(); try { while(c.hasNext()) { System.out.println(c.next()); } } finally { c.close(); }
Simple findOne query, matching a doc with properyname = value:
DBObject result = collection.findOne(new BasicDBObject("propertyname", "value"));
Find all, sort on property ‘example’ ascending (1=asc, -1=desc), and limit to 10 results:
DBCursor c = collection.find() .sort(new BasicDBObject("example", 1)) .limit(10);
Serialize results of a cursor to JSON (tip from here):
JSON json = new JSON(); String jsonString = json.serialize(c);