use of org.bson.BsonString in project graylog2-server by Graylog2.
the class MongoDBVersionCheck method getVersion.
public static Version getVersion(MongoClient mongoClient) {
final MongoDatabase adminDb = mongoClient.getDatabase("admin");
try {
final Document buildInfoResult = adminDb.runCommand(new BsonDocument("buildinfo", new BsonString("")));
if (!buildInfoResult.isEmpty()) {
Object result = buildInfoResult.get("versionArray");
if (!(result instanceof ArrayList)) {
LOG.warn("Couldn't retrieve MongoDB buildInfo");
return null;
}
@SuppressWarnings("rawtypes") final ArrayList versionArray = buildInfoResult.get("versionArray", ArrayList.class);
if (versionArray == null || versionArray.size() < 3) {
LOG.debug("Couldn't retrieve MongoDB version");
return null;
}
final int majorVersion = (int) versionArray.get(0);
final int minorVersion = (int) versionArray.get(1);
final int patchVersion = (int) versionArray.get(2);
return Version.forIntegers(majorVersion, minorVersion, patchVersion);
} else {
LOG.warn("Couldn't retrieve MongoDB buildInfo");
return null;
}
} catch (MongoException e) {
LOG.warn("Couldn't retrieve MongoDB buildInfo", e);
return null;
}
}
use of org.bson.BsonString in project realm-java by realm.
the class ChangeEvent method toBsonDocument.
/**
* Serializes this change event into a {@link BsonDocument}.
*
* @return the serialized document.
*/
@Override
public BsonDocument toBsonDocument() {
final BsonDocument asDoc = new BsonDocument();
asDoc.put(Fields.ID_FIELD, id);
asDoc.put(Fields.OPERATION_TYPE_FIELD, new BsonString(toRemote(getOperationType())));
final BsonDocument nsDoc = new BsonDocument();
nsDoc.put(Fields.NS_DB_FIELD, new BsonString(ns.getDatabaseName()));
nsDoc.put(Fields.NS_COLL_FIELD, new BsonString(getNamespace().getCollectionName()));
asDoc.put(Fields.NS_FIELD, nsDoc);
asDoc.put(Fields.DOCUMENT_KEY_FIELD, getDocumentKey());
DocumentT fullDocument = getFullDocument();
if ((fullDocument instanceof BsonValue) && ((BsonValue) fullDocument).isDocument()) {
asDoc.put(Fields.FULL_DOCUMENT_FIELD, (BsonValue) fullDocument);
}
UpdateDescription updateDescription = getUpdateDescription();
if (updateDescription != null) {
asDoc.put(Fields.UPDATE_DESCRIPTION_FIELD, updateDescription.toBsonDocument());
}
asDoc.put(Fields.WRITE_PENDING_FIELD, new BsonBoolean(hasUncommittedWrites()));
return asDoc;
}
use of org.bson.BsonString in project spring-data-mongodb by spring-projects.
the class ChangeStreamTaskUnitTests method shouldNotBreakLovelaceBehavior.
// DATAMONGO-2258
@Test
void shouldNotBreakLovelaceBehavior() {
BsonDocument resumeToken = new BsonDocument("token", new BsonString(UUID.randomUUID().toString()));
when(changeStreamIterable.resumeAfter(any())).thenReturn(changeStreamIterable);
ChangeStreamRequest request = //
ChangeStreamRequest.builder().collection(//
"start-wars").resumeToken(//
resumeToken).publishTo(//
message -> {
}).build();
initTask(request, Document.class);
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
}
use of org.bson.BsonString in project spring-data-mongodb by spring-projects.
the class ChangeStreamTaskUnitTests method shouldApplyStartAfterToChangeStream.
// DATAMONGO-2258
@Test
void shouldApplyStartAfterToChangeStream() {
when(changeStreamIterable.startAfter(any())).thenReturn(changeStreamIterable);
BsonDocument resumeToken = new BsonDocument("token", new BsonString(UUID.randomUUID().toString()));
ChangeStreamRequest request = //
ChangeStreamRequest.builder().collection(//
"start-wars").startAfter(//
resumeToken).publishTo(//
message -> {
}).build();
initTask(request, Document.class);
verify(changeStreamIterable).startAfter(eq(resumeToken));
}
use of org.bson.BsonString in project spring-data-mongodb by spring-projects.
the class ChangeStreamTaskUnitTests method shouldApplyResumeAfterToChangeStream.
// DATAMONGO-2258
@Test
void shouldApplyResumeAfterToChangeStream() {
when(changeStreamIterable.resumeAfter(any())).thenReturn(changeStreamIterable);
BsonDocument resumeToken = new BsonDocument("token", new BsonString(UUID.randomUUID().toString()));
ChangeStreamRequest request = //
ChangeStreamRequest.builder().collection(//
"start-wars").resumeAfter(//
resumeToken).publishTo(//
message -> {
}).build();
initTask(request, Document.class);
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
}
Aggregations