mongo api,distinct查询后,循环查询

为了减轻手工查询,测试对比数据的工作量。写成代码还挺好用的,在这里记录下:

import com.mongodb.*;
import java.util.List;

public class Test3 {
        public static void main(String[] args){
        try {
            MongoURI uri = new MongoURI("mongodb://IP:端口/test2");//Constants.DIC_DB_ADDR);
            // Open the db
            Mongo mongo = new Mongo(uri);
            DB db = mongo.getDB(uri.getDatabase());
            int sum=0;
            DBCollection coll = db.getCollection("test");//Constants.DIC_TABLE);
          /*  DBObject greatThanEqualAndLessThanEqual=new BasicDBObject();
            greatThanEqualAndLessThanEqual.put("$gte", "1446620400000");
            greatThanEqualAndLessThanEqual.put("$lt", "1446624000000");
            DBObject orGreatThan=new BasicDBObject("err","0");
            DBObject orGreatThan2=new BasicDBObject("err","-");*/

            DBObject ageCompare=new BasicDBObject();
            DBObject distinctkey=new BasicDBObject();
     /*       ageCompare.put("pid","10014326");
            ageCompare.put("ac", "time");
            ageCompare.put("p1", "2");*/
            List<String> lidList = coll.distinct("lid");
            for(int x=0;x<lidList.size();x++) {
                for (long i = 1455520200000l; i < 1455606600000l; i = i + 300000) {

                    ageCompare.put("lid", lidList.get(x));
                    //ageCompare.put("ty", "1");
                    ageCompare.put("ts", i);
                    DBCursor cur = coll.find(ageCompare);
                    //System.out.println(cur.count());
                    if (cur.count() == 2)
                        System.out.println(lidList.get(x)+":"+i);
                }
            }
            //ageCompare.put("$or", new Object[]{orGreatThan,orGreatThan2});

             int result;

            //System.out.println(sum);

            mongo.close();
        }  catch (Exception e) {
            // Die fast
            throw new RuntimeException(e);
        }

    }
}

展开阅读全文

没有更多推荐了,返回首页