use of com.mongodb.client.MongoCollection in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addUserComment.
public String addUserComment() {
MongoCollection collection = null;
Document query = null;
try {
// add a comment from user Melanie
String who = "Melanie";
Document comment = new Document("_id", who).append("name", who).append("address", new BasicDBObject("street", "123 Main Street").append("city", "Fastville").append("state", "MA").append("zip", 18180)).append("comment", "I really love your new website but I have a lot of questions about using NoSQL versus a traditional RDBMS. " + "I would like to sign up for your 'MongoDB Is Web Scale' training session.");
// save the comment
collection = database.getCollection("comments");
collection.insertOne(comment);
// look up the comment from Melanie
query = new Document("_id", who);
FindIterable cursor = collection.find(query);
Object userComment = cursor.first();
return userComment.toString();
} finally {
collection.drop();
}
}
use of com.mongodb.client.MongoCollection in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManager method select.
@Override
public List<DocumentEntity> select(DocumentQuery query) {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
return stream(collection.find(mongoDBQuery).spliterator(), false).map(MongoDBUtils::of).map(ds -> DocumentEntity.of(collectionName, ds)).collect(toList());
}
use of com.mongodb.client.MongoCollection in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManager method update.
@Override
public DocumentEntity update(DocumentEntity entity) {
DocumentEntity copy = entity.copy();
String collectionName = entity.getName();
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
Document id = copy.find(ID_FIELD).map(d -> new Document(d.getName(), d.getValue().get())).orElseThrow(() -> new UnsupportedOperationException("To update this DocumentEntity " + "the field `id` is required"));
copy.remove(ID_FIELD);
collection.findOneAndReplace(id, getDocument(entity));
return entity;
}
use of com.mongodb.client.MongoCollection in project presto by prestodb.
the class MongoSession method createTableMetadata.
private void createTableMetadata(SchemaTableName schemaTableName, List<MongoColumnHandle> columns) throws TableNotFoundException {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
MongoDatabase db = client.getDatabase(schemaName);
Document metadata = new Document(TABLE_NAME_KEY, tableName);
ArrayList<Document> fields = new ArrayList<>();
if (!columns.stream().anyMatch(c -> c.getName().equals("_id"))) {
fields.add(new MongoColumnHandle("_id", OBJECT_ID, true).getDocument());
}
fields.addAll(columns.stream().map(MongoColumnHandle::getDocument).collect(toList()));
metadata.append(FIELDS_KEY, fields);
MongoCollection<Document> schema = db.getCollection(schemaCollection);
schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
schema.insertOne(metadata);
}
use of com.mongodb.client.MongoCollection in project legendarybot by greatman.
the class CustomCommandsPlugin method start.
@Override
public void start() {
log.info("Loading custom commands");
getBot().getJDA().forEach(jda -> jda.getGuilds().forEach(g -> {
MongoCollection<Document> collection = getBot().getMongoDatabase().getCollection(MONGO_COLLECTION_NAME);
Map<String, String> result = new HashMap<>();
collection.find(eq("guild_id", g.getId())).forEach((Block<Document>) document -> {
if (document.containsKey(MONGO_DOCUMENT_NAME)) {
((Document) document.get(MONGO_DOCUMENT_NAME)).forEach((k, v) -> {
System.out.println("GUILD:" + g.getId() + " key: " + k + " value: " + v);
result.put(k, (String) v);
});
}
});
guildCustomCommands.put(g.getId(), result);
}));
getBot().getJDA().forEach(jda -> jda.addEventListener(listener));
log.info("Custom commands loaded");
getBot().getCommandHandler().setUnknownCommandHandler(new IUnknownCommandHandler(this));
getBot().getCommandHandler().addCommand("createcmd", new CreateCommand(this), "Custom Commands Admin Commands");
getBot().getCommandHandler().addCommand("removecmd", new RemoveCommand(this), "Custom Commands Admin Commands");
getBot().getCommandHandler().addCommand("listcommands", new ListCommand(this), "General Commands");
log.info("Plugin Custom Commands loaded!");
log.info("Command !createcmd loaded!");
}
Aggregations