本文整理了Java中org.bson.conversions.Bson
类的一些代码示例,展示了Bson
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bson
类的具体详情如下:
包路径:org.bson.conversions.Bson
类名称:Bson
[英]An interface for types that are able to render themselves into a BsonDocument.
[中]类型的接口,这些类型能够将自己呈现到BsonDocument中。
代码示例来源:origin: org.mongodb/mongo-java-driver
BsonDocument toBsonDocumentOrNull(final Bson document) {
return document == null ? null : document.toBsonDocument(documentClass, codecRegistry);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
private BsonDocument toBsonDocument(final Bson bson) {
return bson == null ? null : bson.toBsonDocument(documentClass, codecRegistry);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
private List<BsonDocument> createBsonDocumentList(final List<? extends Bson> pipeline) {
List<BsonDocument> aggregateList = new ArrayList<BsonDocument>(pipeline.size());
for (Bson obj : pipeline) {
if (obj == null) {
throw new IllegalArgumentException("pipeline cannot contain a null value");
}
aggregateList.add(obj.toBsonDocument(BsonDocument.class, codecRegistry));
}
return aggregateList;
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
private List<BsonDocument> createBsonDocumentList(final List<? extends Bson> pipeline) {
notNull("pipeline", pipeline);
List<BsonDocument> bsonDocumentPipeline = new ArrayList<BsonDocument>(pipeline.size());
for (Bson obj : pipeline) {
if (obj == null) {
throw new IllegalArgumentException("pipeline can not contain a null value");
}
bsonDocumentPipeline.add(obj.toBsonDocument(BsonDocument.class, codecRegistry));
}
return bsonDocumentPipeline;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
return new BsonDocument(name, value.toBsonDocument(documentClass, codecRegistry));
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Nullable
private BsonValue getOutCollection() {
if (pipeline.size() == 0) {
return null;
}
Bson lastStage = notNull("last stage", pipeline.get(pipeline.size() - 1));
return lastStage.toBsonDocument(documentClass, codecRegistry).get("$out");
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Nullable
private BsonDocument toBsonDocument(@Nullable final Bson document) {
return document == null ? null : document.toBsonDocument(BsonDocument.class, codecRegistry);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Get a list of index names for the given list of index models
*
* @param indexes the index models
* @param codecRegistry the codec registry to convert each Bson key to a BsonDocument
* @return the list of index names
*/
public static List<String> getIndexNames(final List<IndexModel> indexes, final CodecRegistry codecRegistry) {
List<String> indexNames = new ArrayList<String>(indexes.size());
for (IndexModel index : indexes) {
String name = index.getOptions().getName();
if (name != null) {
indexNames.add(name);
} else {
indexNames.add(IndexHelper.generateIndexName(index.getKeys().toBsonDocument(BsonDocument.class, codecRegistry)));
}
}
return indexNames;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
return new BsonDocument(fieldName, new BsonDocument("$elemMatch", filter.toBsonDocument(documentClass, codecRegistry)));
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
return new BsonDocument(fieldName, new BsonDocument("$elemMatch", filter.toBsonDocument(documentClass, codecRegistry)));
}
};
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonDocument filterDocument = filter.toBsonDocument(documentClass, codecRegistry);
if (filterDocument.size() == 1) {
Map.Entry<String, BsonValue> entry = filterDocument.entrySet().iterator().next();
return createFilter(entry.getKey(), entry.getValue());
} else {
BsonArray values = new BsonArray();
for (Map.Entry<String, BsonValue> docs : filterDocument.entrySet()) {
values.add(new BsonDocument(docs.getKey(), docs.getValue()));
}
return createFilter("$and", values);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
DropIndexOperation dropIndex(final Bson keys, final DropIndexOptions dropIndexOptions) {
return new DropIndexOperation(namespace, keys.toBsonDocument(BsonDocument.class, codecRegistry), writeConcern)
.maxTime(dropIndexOptions.getMaxTime(MILLISECONDS), MILLISECONDS);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> tDocumentClass, final CodecRegistry codecRegistry) {
BsonDocument document = new BsonDocument();
for (Bson update : updates) {
BsonDocument rendered = update.toBsonDocument(tDocumentClass, codecRegistry);
for (Map.Entry<String, BsonValue> element : rendered.entrySet()) {
if (document.containsKey(element.getKey())) {
BsonDocument currentOperatorDocument = (BsonDocument) element.getValue();
BsonDocument existingOperatorDocument = document.getDocument(element.getKey());
for (Map.Entry<String, BsonValue> currentOperationDocumentElements : currentOperatorDocument.entrySet()) {
existingOperatorDocument.append(currentOperationDocumentElements.getKey(),
currentOperationDocumentElements.getValue());
}
} else {
document.append(element.getKey(), element.getValue());
}
}
}
return document;
}
代码示例来源:origin: immutables/immutables
/**
* Convert criteria to mongo query (for testing). Currently using reflection (since exposed
* only in tests).
*
* @return Query (as {@link BsonDocument}) which will be sent to mongo.
*/
public static BsonDocument extractQuery(Repositories.Criteria criteria) {
Preconditions.checkNotNull(criteria, "criteria");
try {
final Field field = criteria.getClass().getDeclaredField("constraint");
field.setAccessible(true);
Constraints.Constraint constraint = (Constraints.Constraint) field.get(criteria);
return Support.convertToBson(constraint)
.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry());
} catch (NoSuchFieldException e) {
throw new RuntimeException("private field 'constraint' not found in " + criteria, e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonDocument compoundIndex = new BsonDocument();
for (Bson index : indexes) {
BsonDocument indexDocument = index.toBsonDocument(documentClass, codecRegistry);
for (String key : indexDocument.keySet()) {
compoundIndex.append(key, indexDocument.get(key));
}
}
return compoundIndex;
}
};
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonDocument combinedDocument = new BsonDocument();
for (Bson sort : sorts) {
BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry);
for (String key : sortDocument.keySet()) {
combinedDocument.append(key, sortDocument.get(key));
}
}
return combinedDocument;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonDocument orRenderable = new BsonDocument();
BsonArray filtersArray = new BsonArray();
for (Bson filter : filters) {
filtersArray.add(filter.toBsonDocument(documentClass, codecRegistry));
}
orRenderable.put(operator.name, filtersArray);
return orRenderable;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonDocument combinedDocument = new BsonDocument();
for (Bson sort : projections) {
BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry);
for (String key : sortDocument.keySet()) {
combinedDocument.remove(key);
combinedDocument.append(key, sortDocument.get(key));
}
}
return combinedDocument;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
<TResult> DistinctOperation<TResult> distinct(final String fieldName, final Bson filter,
final Class<TResult> resultClass, final long maxTimeMS,
final Collation collation) {
return new DistinctOperation<TResult>(namespace, fieldName, codecRegistry.get(resultClass))
.filter(filter == null ? null : filter.toBsonDocument(documentClass, codecRegistry))
.maxTime(maxTimeMS, MILLISECONDS)
.collation(collation);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@SuppressWarnings("unchecked")
static <TItem> void encodeValue(final BsonDocumentWriter writer, final TItem value, final CodecRegistry codecRegistry) {
if (value == null) {
writer.writeNull();
} else if (value instanceof Bson) {
((Encoder) codecRegistry.get(BsonDocument.class)).encode(writer,
((Bson) value).toBsonDocument(BsonDocument.class, codecRegistry),
EncoderContext.builder().build());
} else {
((Encoder) codecRegistry.get(value.getClass())).encode(writer, value, EncoderContext.builder().build());
}
}
内容来源于网络,如有侵权,请联系作者删除!