Package org.mongodb

Examples of org.mongodb.Document


  }

  public CompletableFuture<T> insert(T elem) {
    CompletableFuture<T> future = new CompletableFuture<>();
    try {
      Document doc = Document.valueOf(mapper.writeValueAsString(elem));
      collection.insert(doc).register((result, e) -> {
        if (result != null && result.wasAcknowledged()) {
          elem.setId(doc.getObjectId("_id"));
          future.complete(elem);
        } else {
          logger.error("Error while creating a new document in insert() : " + doc.toString(), e);
          future.cancel(true);
        }
      });
    } catch (JsonProcessingException e) {
      logger.error("Error while creating element " + elem.toString() + " in insert()", e);
View Full Code Here


  }

  public CompletableFuture<T> getOne(String key, Object value) {
    CompletableFuture<T> future = new CompletableFuture<>();

    collection.find(new Document(key, value)).one().register((document, e) -> {
        try {
          if (document != null) {
            future.complete(mapper.readValue(document.toString(), clazz));
          } else {
            logger.error("No document with attribute " + key + "=" + value + " found",  e);
View Full Code Here

  public CompletableFuture<List<T>> getSome(String key, Object value) {
    CompletableFuture<List<T>> future = new CompletableFuture<>();
    List<T> list = new ArrayList<>();

    collection.find(new Document(key, value)).forEach((document) -> {
      try {
        list.add(mapper.readValue(document.toString(), clazz));
      } catch (IOException e) {
        logger.error("Error while parsing document in getSome() : " + document.toString(), e);
      }
View Full Code Here

    throw new UnsupportedOperationException("Remove operation not yet implemented in MongoDB async driver");
  }

  public CompletableFuture<Long> count(String key, Object value) {
    CompletableFuture<Long> future = new CompletableFuture<>();
    collection.find(new Document(key, value)).count().register((count, e) -> future.complete(count));
    return future;
  }
View Full Code Here

    return snapRepository.getById(id);
  }

  @Override
  public CompletableFuture<List<Snap>> getSnapsFromRecipient(String username) {
    return snapRepository.getSome("recipient", new Document("$elemMatch" , new Document("username", username)));
  }
View Full Code Here

TOP

Related Classes of org.mongodb.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.