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:org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient.java

License:Apache License

public void update(ServerConfiguration configuration, SingleMongoCollection singleMongoCollection,
        Document mongoDocument) {
    MongoClient mongo = null;/*from ww w  .  ja v a 2  s.  c o  m*/
    try {
        String databaseName = singleMongoCollection.getDatabaseName();
        mongo = createMongoClient(configuration);

        MongoDatabase database = mongo.getDatabase(databaseName);
        MongoCollection<Document> collection = database.getCollection(singleMongoCollection.getName());

        final Object id = mongoDocument.get("_id");
        if (id == null) {
            collection.insertOne(mongoDocument);
        } else {
            collection.replaceOne(Filters.eq("_id", id), mongoDocument);
        }
    } catch (UnknownHostException ex) {
        throw new ConfigurationException(ex);
    } finally {
        if (mongo != null) {
            mongo.close();
        }
    }
}

From source file:org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient.java

License:Apache License

public void delete(ServerConfiguration configuration, SingleMongoCollection singleMongoCollection, Object _id) {
    MongoClient mongo = null;//from   w w  w  .j a  v  a2  s  .  c o m
    try {
        String databaseName = singleMongoCollection.getDatabaseName();
        mongo = createMongoClient(configuration);

        MongoDatabase database = mongo.getDatabase(databaseName);
        MongoCollection<Document> collection = database.getCollection(singleMongoCollection.getName());
        collection.deleteOne(Filters.eq("_id", _id));
    } catch (UnknownHostException ex) {
        throw new ConfigurationException(ex);
    } finally {
        if (mongo != null) {
            mongo.close();
        }
    }
}

From source file:org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient.java

License:Apache License

public Document findMongoDocument(ServerConfiguration configuration,
        SingleMongoCollection singleMongoCollection, Object _id) {
    MongoClient mongo = null;//  www.  j a v a 2 s  . c om
    try {
        String databaseName = singleMongoCollection.getDatabaseName();
        mongo = createMongoClient(configuration);

        MongoDatabase database = mongo.getDatabase(databaseName);
        com.mongodb.client.MongoCollection<Document> collection = database
                .getCollection(singleMongoCollection.getName());
        return collection.find(Filters.eq("_id", _id)).first();
    } catch (UnknownHostException ex) {
        throw new ConfigurationException(ex);
    } finally {
        if (mongo != null) {
            mongo.close();
        }
    }
}

From source file:org.dcache.sf.FlushTask.java

License:Open Source License

@Override
public Set<URI> start() throws IOException {
    files.find(Filters.eq("pnfsid", pnfsId.getId()));
    files.insertOne(new Document("pnfsid", pnfsId.getId()));

    return null;/* w w  w.  j  av a  2  s .com*/
}

From source file:org.dcache.sf.FlushTask.java

License:Open Source License

@Override
public Set<URI> poll() throws URISyntaxException {
    FindIterable<Document> result = files
            .find(Filters.and(Filters.eq("pnfsid", pnfsId.getId()), Filters.exists("bfid")));
    final Set<URI> uris = new HashSet<>();
    result.forEach(new Block<Document>() {
        @Override//from   ww w. ja  v  a2  s. c o  m
        public void apply(Document document) {
            try {
                String uriString = document.get("bfid").toString();
                uris.add(new URI(uriString));
            } catch (URISyntaxException e) {
                System.out.println(e.getMessage());
            }
        }
    });
    return uris;
}

From source file:org.dcache.sf.FlushTask.java

License:Open Source License

@Override
public boolean abort() throws IOException {
    return files.findOneAndDelete(Filters.eq("pnfsid", pnfsId.getId())) != null;
}

From source file:org.eclipse.ditto.services.thingsearch.persistence.read.criteria.visitors.CreateBsonPredicateVisitor.java

License:Open Source License

@Override
public Function<String, Bson> visitEq(final Object value) {
    return fieldName -> Filters.eq(fieldName, value);
}

From source file:org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.GetExistsBsonVisitor.java

License:Open Source License

@Override
Bson visitPointer(final String pointer) {
    return getAuthorizationBson()
            .map(authBson -> Filters.elemMatch(FIELD_INTERNAL,
                    Filters.and(authBson, Filters.eq(FIELD_INTERNAL_KEY, pointer))))
            .orElseGet(() -> Filters.eq(FIELD_PATH_KEY, pointer));
}

From source file:org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.GetFilterBsonVisitor.java

License:Open Source License

private Bson matchKeyValue(final String key) {
    final Bson keyValueFilter = Filters.and(Filters.eq(FIELD_INTERNAL_KEY, key), valueFilter);
    return Filters.elemMatch(FIELD_INTERNAL, getAuthorizationBson()
            .map(authBson -> Filters.and(keyValueFilter, authBson)).orElse(keyValueFilter));
}

From source file:org.eclipse.ditto.services.thingsearch.persistence.write.model.AbstractWriteModel.java

License:Open Source License

/**
 * Get the filter of this write model.//  w  ww. j a  v a 2  s.com
 *
 * @return filter on search index documents.
 */
public Bson getFilter() {
    return Filters.and(Filters.eq(FIELD_ID, new BsonString(metadata.getThingId().toString())));
}