将BsonDocument转换为文档

时间:2018-12-14 11:12:49

标签: java mongodb spring-data-mongodb mongo-java-driver

我想知道以下几行是否是org.bson.BsonDocumentorg.bson.Document的有效转换。

实际上,我想使用org.springframework.data.mongodb.core.query.Creteria重写com.mongodb.client.model.Filters的and运算符

class MyAndCriteria extends Criteria {
        private Criteria left;
        private Criteria right;

        public MyAndCriteria(Criteria left, Criteria right) {
            this.left = left;
            this.right = right;
        }

        @Override
        public Document getCriteriaObject() {
            BsonDocument bsonDocument = Filters.and(left.getCriteriaObject(), right.getCriteriaObject()).toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry());
            return Document.parse(bsonDocument.toJson());
        }
    }

0 个答案:

没有答案