mongodb多字段排序

//db.role_level_rank.find().sort({"level":-1,"rankTime":1})

        MongoClient m1 = new MongoClient("localhost");
        DB db = m1.getDB("test");
        DBCollection col = db.getCollection("car");
        DBObject query = new BasicDBObject("speed",
                new BasicDBObject("$gt", 40));
        // fields with name and speed field is specified and only these fields
        // are displayed
        BasicDBObject fields = new BasicDBObject("name", 1).append("speed", 1);
        DBCursor carCursor1 = col.find(query, fields);
        try {
            while (carCursor1.hasNext()) {
                System.out.println(carCursor1.next());
            }
        } finally {
            carCursor1.close();
        }

 

转载于:https://my.oschina.net/u/2246708/blog/1922047

你可能感兴趣的:(mongodb多字段排序)