ㄓㄤㄑㄧㄤ

java操作Mongodb

public class TagSampleTemplate {

    /**
     * 
     */
    public TagSampleTemplate() {
    }

    @Autowired
    private MongoTemplate mongoTemplate;
    
    public ArrayList<DBObject> findByTag(String tag){
        DBCollection collection = mongoTemplate.getCollection("tagSample");
        DBObject query = new BasicDBObject();
        query.put("tag", tag);
        
        DBObject sort = new BasicDBObject();
        sort.put("tagCount", -1);
        DBCursor cursor = collection.find(query).sort(sort);
        ArrayList<DBObject> l = Lists.newArrayList(cursor.iterator());
        for(DBObject o : l){
            System.out.println(o);
        }
        return l;
    }
}

 

posted @ 2016-06-16 17:46  ㄓㄤㄑㄧㄤ  阅读(256)  评论(0编辑  收藏  举报
哈哈,页脚部分。