Skip to main content

Posts

Showing posts from October, 2012
Why we Use MongoDB? Here is some highlights:- For more kindly visit  mongodb site:- http://www.mongodb.org/display/DOCS/Introduction Document-oriented Dynamically-typed (schemaless) for easy schema evolution Embedded documents and arrays reduce need for joins Documents (objects) map nicely to programming language data types High performance Indexes including indexing of keys from embedded documents and arrays Optional streaming writes (no acknowledgements) No joins and embedding makes reads and writes fast High availability Easy scalability Eventually-consistent reads can be distributed over replicated servers Automatic sharding (auto-partitioning of data across servers) Reads and writes are distributed over shards No joins or multi-document transactions make distributed queries easy and fast Rich query language
How to get Data in sorted form in spring mongodb Create Query Object and pass your Query Criteria into Query Query query=new Query (criteria); Then Query.sort().on(“sortOnTheBasicOf”, Order . ASCENDING ); Order. ASCENDING for get result in asending order and Order . DESCENDING to get result in Desending order.. sortOnTheBasicOf à Pass the entity name by which you want to sort Pass this query to Your Mangotemplate and Your Class from which You want to get Result  mongoTemplate.find(query, YourEntityClassName.class); Then You Got Desired Out put Cheers !!!!!!!!!!!!!!!!!

How To Use Map Reduce in Spring Mongo data

Suppose  I have order table and I want to find out best five selling product. Create a method that returns best product of ValueObject Type . ValueObject Type basically contain id and corresponding values to those ids as shown below: public class ValueObject implements Comparable<ValueObject>{ private Object id; private int value; public Object getId() { return id; } public void setId(Object id) { this.id = id; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } @Override public String toString() { return "ValueObject [id=" + id + ", value=" + value + "]"; } @Override public int compareTo(ValueObject o) { if(o instanceof ValueObject){ return o.getValue()-this.getValue(); } else{ throw new ClassCastException(); } } } Now, you can call mapReduce method on MongoTemplate which retur