Example usage for com.mongodb.client.model Filters eq

List of usage examples for com.mongodb.client.model Filters eq

Introduction

In this page you can find the example usage for com.mongodb.client.model Filters eq.

Prototype

public static <TItem> Bson eq(final String fieldName, @Nullable final TItem value) 

Source Link

Document

Creates a filter that matches all documents where the value of the field name equals the specified value.

Usage

From source file:net.netzgut.integral.mongo.internal.services.MongoODMImplementation.java

License:Apache License

@Override
public <T extends Serializable> UpdateResult upsert(Bson filter, T entity) {
    Class<? extends Serializable> entityClass = entity.getClass();
    MongoCollection<Document> collection = this.mongo.getCollection(entityClass);
    Document document = this.converter.documentFrom(entity);
    Bson update = Filters.eq("$set", document);
    return collection.updateOne(filter, update, new UpdateOptions().upsert(true));
}

From source file:net.netzgut.integral.mongo.internal.services.MongoODMImplementation.java

License:Apache License

@Override
public <T extends Serializable> UpdateResult update(Bson filter, T entity) {
    Class<? extends Serializable> entityClass = entity.getClass();
    MongoCollection<Document> collection = this.mongo.getCollection(entityClass);
    Document document = this.converter.documentFrom(entity);
    Bson update = Filters.eq("$set", document);
    return collection.updateOne(filter, update);
}

From source file:net.netzgut.integral.mongo.internal.services.MongoODMImplementation.java

License:Apache License

@Override
public <T extends Serializable> UpdateResult update(Bson filter, Class<T> entityClass,
        Map<String, Object> updateMap) {
    MongoCollection<Document> collection = this.mongo.getCollection(entityClass);
    Bson update = Filters.eq("$set", new Document(updateMap));
    return collection.updateOne(filter, update);
}

From source file:org.apache.drill.exec.store.mongo.config.MongoPersistentStore.java

License:Apache License

@Override
public V get(String key) {
    try {/*from  w  w w  . j a v a  2s.  c o m*/
        Bson query = Filters.eq(DrillMongoConstants.ID, key);
        Document document = collection.find(query).first();
        if (document != null) {
            return value((byte[]) document.get(pKey));
        } else {
            return null;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new DrillRuntimeException(e.getMessage(), e);
    }
}

From source file:org.apache.drill.exec.store.mongo.config.MongoPersistentStore.java

License:Apache License

@Override
public boolean putIfAbsent(String key, V value) {
    try {//from  ww  w  . j a va2s . c om
        Bson query = Filters.eq(DrillMongoConstants.ID, key);
        Bson update = Updates.set(pKey, bytes(value));
        UpdateResult updateResult = collection.updateOne(query, update, new UpdateOptions().upsert(true));
        return updateResult.getModifiedCount() == 1;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new DrillRuntimeException(e.getMessage(), e);
    }
}

From source file:org.apache.drill.exec.store.mongo.config.MongoPersistentStore.java

License:Apache License

@Override
public void delete(String key) {
    try {//ww  w. j  ava 2s.  c  om
        Bson query = Filters.eq(DrillMongoConstants.ID, key);
        collection.deleteOne(query);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new DrillRuntimeException(e.getMessage(), e);
    }
}

From source file:org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage.java

License:Apache License

@Override
public Optional<Entity> get(final RyaURI subject) throws EntityStorageException {
    requireNonNull(subject);/*  w  ww. j  a va 2 s .  c o  m*/

    try {
        final Document document = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME)
                .find(Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData())).first();

        return document == null ? Optional.empty() : Optional.of(ENTITY_CONVERTER.fromDocument(document));

    } catch (final MongoException | DocumentConverterException e) {
        throw new EntityStorageException("Could not get the Entity with Subject '" + subject.getData() + "'.",
                e);
    }
}

From source file:org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage.java

License:Apache License

private static Bson makeSubjectFilter(final RyaURI subject) {
    return Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData());
}

From source file:org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage.java

License:Apache License

private static Bson makeVersionFilter(final int version) {
    return Filters.eq(EntityDocumentConverter.VERSION, version);
}

From source file:org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage.java

License:Apache License

private static Bson makeExplicitTypeFilter(final RyaURI typeId) {
    return Filters.eq(EntityDocumentConverter.EXPLICIT_TYPE_IDS, typeId.getData());
}