use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method rename.
@Override
public void rename(final BsonValue id, final String newFilename, final SingleResultCallback<Void> callback) {
notNull("id", id);
notNull("newFilename", newFilename);
notNull("callback", callback);
final SingleResultCallback<Void> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
filesCollection.updateOne(new BsonDocument("_id", id), new BsonDocument("$set", new BsonDocument("filename", new BsonString(newFilename))), new SingleResultCallback<UpdateResult>() {
@Override
public void onResult(final UpdateResult result, final Throwable t) {
if (t != null) {
errHandlingCallback.onResult(null, t);
} else if (result.wasAcknowledged() && result.getMatchedCount() == 0) {
errHandlingCallback.onResult(null, new MongoGridFSException(format("No file found with the ObjectId: %s", id)));
} else {
errHandlingCallback.onResult(null, null);
}
}
});
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class ClientMetadataHelper method listToBsonString.
static BsonString listToBsonString(final List<String> listOfStrings) {
StringBuilder stringBuilder = new StringBuilder();
int i = 0;
for (String val : listOfStrings) {
if (i > 0) {
stringBuilder.append(SEPARATOR);
}
stringBuilder.append(val);
i++;
}
return new BsonString(stringBuilder.toString());
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class GetMoreProtocol method asGetMoreCommandResponseDocument.
private BsonDocument asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) {
List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
if (responseBuffers.getReplyHeader().getNumberReturned() != 0) {
responseBuffers.getBodyByteBuffer().position(0);
rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
}
BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("nextBatch", new BsonArray(rawResultDocuments));
return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class IndexHelper method generateIndexName.
/**
* Convenience method to generate an index name from the set of fields it is over.
*
* @return a string representation of this index's fields
*/
static String generateIndexName(final BsonDocument index) {
StringBuilder indexName = new StringBuilder();
for (final String keyNames : index.keySet()) {
if (indexName.length() != 0) {
indexName.append('_');
}
indexName.append(keyNames).append('_');
BsonValue ascOrDescValue = index.get(keyNames);
if (ascOrDescValue instanceof BsonNumber) {
indexName.append(((BsonNumber) ascOrDescValue).intValue());
} else if (ascOrDescValue instanceof BsonString) {
indexName.append(((BsonString) ascOrDescValue).getValue().replace(' ', '_'));
}
}
return indexName.toString();
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class ListCollectionsOperation method projectFromFullNamespaceToCollectionName.
private List<T> projectFromFullNamespaceToCollectionName(final List<BsonDocument> unstripped) {
if (unstripped == null) {
return null;
}
List<T> stripped = new ArrayList<T>(unstripped.size());
String prefix = databaseName + ".";
for (BsonDocument cur : unstripped) {
String name = cur.getString("name").getValue();
String collectionName = name.substring(prefix.length());
cur.put("name", new BsonString(collectionName));
stripped.add(decoder.decode(new BsonDocumentReader(cur), DecoderContext.builder().build()));
}
return stripped;
}
Aggregations