Skip to main content

Posts

Showing posts from March, 2013

Check to size of collection in MongoDB

db.collection.dataSize(): data size for the collection. db.collection.storageSize(): allocation size, including unused space. db.collection.totalSize(): the data size plus the index size. db.collection.totalIndexSize(): the index size. PRIMARY> mdb = db.getSiblingDB("myDbName") PRIMARY> mdb.getCollectionNames().forEach(function(c) { s = mdb[c].stats(); printjson(s)} )

Selected data copy to an other collection

PRIMARY> db.orders.find().forEach(printjson) {  "_id" : ObjectId("513466b691390735f2237119"),  "category" : "blue",  "recordDate" : ISODate("2012-04-02T17:04:11.105Z"),  "status" : "A",  "price" : 50 } {  "_id" : ObjectId("513466e591390735f223711a"),  "category" : "red",  "recordDate" : ISODate("2012-04-02T10:05:11.105Z"),  "status" : "A",  "price" : 60 } {  "_id" : ObjectId("5134689291390735f223711b"),  "category" : "red",  "recordDate" : ISODate("2012-04-02T10:05:11.105Z"),  "status" : "A",  "price" : 60 } PRIMARY> var docs = db.orders.find({ "category" : "red"}); PRIMARY> db.orders.find().forEach(printjson) {  "_id" : ObjectId("513466e591390735f2...

Property Loader

loading property and configuration files in Java   import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Properties; public class LoadProperties {        private static LoadProperties instance = null;         private Properties properties = new Properties();         public static void main(String[] args) {         LoadProperties instance = LoadProperties.getInstance();         instance.testProperties();     }    protected LoadProperties() {        FileReader fileReader;         try {             fileReader = new FileReader(new File("/home/ercan/config.properties"));            ...

Postgresql Test Data

SELECT generate_series(1,1000) as key ,(random()*10000.)::numeric(6,2) ,repeat('5',(random()*20)::integer) ,substr('abcdefghijklmnopqrstuvwxyz',1, (random()*26)::integer) ,(ARRAY['one','two','three'])[1+random()*3] ,(random()*(9*10^18))::bigint ;

vi tips and tricks

    Command Summary *    find cursor under word STARTING vi      vi filename    edit a file named "filename"      vi newfile     create a new file named "newfile" ENTERING TEXT      i            insert text left of cursor      a            append text right of cursor MOVING THE CURSOR      h            left one space      j            down one line      k            up one line      l            right one space BASIC EDITING ...

PostgreSQL before insert Trigger

CREATE FUNCTION update_person_operation_date() RETURNS TRIGGER AS $$ BEGIN     UPDATE person SET operation_date=now() WHERE person_id=NEW.person_id;     RETURN NEW; END; $$ LANGUAGE plpgsql; -- then CREATE TRIGGER update_person_operation_date_trigger BEFORE INSERT ON person FOR EACH ROW EXECUTE update_person_operation_date;

MongoDB $where operator sample

@Test     public void testWhereOperator(){                                                                                                                                                                                           DBCollection collection = MongoDBFactory.getCollection("test","orders"); BasicDBObject query = new BasicDBObject(); query.put("cust_id", "abc124"); query.put("status", "A"); query.put("$where", "this.price > 50"); final String code = "var i = 0;" +     ...

Aggregation method with Mongo java driver

PRIMARY> db.orders.find().forEach(printjson) { "_id" : ObjectId("513466b691390735f2237119"), "category" : "blue", "recordDate" : ISODate("2012-04-02T17:04:11.105Z"), "status" : "A", "price" : 50 } { "_id" : ObjectId("513466e591390735f223711a"), "category" : "red", "recordDate" : ISODate("2012-04-02T10:05:11.105Z"), "status" : "A", "price" : 60 } { "_id" : ObjectId("5134689291390735f223711b"), "category" : "red", "recordDate" : ISODate("2012-04-02T10:05:11.105Z"), "status" : "A", "price" : 60 } java test code :  @Test     public void testAggregation(){                                                                                                             ...