private Object negate(BasicDBObject arg) {
        BasicDBList list = new BasicDBList();
        for (Map.Entry<String, Object> entry : arg.entrySet()) {
            if (entry.getKey().equals("$or")) {
                list.add(asDBObject("$nor", entry.getValue()));

            } else if (entry.getKey().equals("$and")) {
                BasicDBList list2 = new BasicDBList();
                for (Object o : ((BasicDBList) entry.getValue())) {
                    list2.add(negate((BasicDBObject) o));
                }
                list.add(asDBObject("$or", list2));

            } else if (entry.getValue() instanceof Pattern) {
                list.add(asDBObject(entry.getKey(), asDBObject("$not", entry.getValue())));

            } else if (entry.getValue() instanceof BasicDBObject) {
                list.add(negate(entry.getKey(), (BasicDBObject) entry.getValue()));

            } else {
                list.add(asDBObject(entry.getKey(), asDBObject("$ne", entry.getValue())));
            }
        }
        return list.size() == 1 ? list.get(0) : asDBObject("$or", list);
    }
Serializes the given Querydsl query to a DBObject query for MongoDB

@author laimw
@author sangyong choi
querydsl-mongodb/src/main/java/com/querydsl/mongodb/MongodbSerializer.java