我想知道以下几行是否是org.bson.BsonDocument
到org.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());
}
}