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:rocks.devonthe.stickychunk.database.MongodbDatabase.java

License:GNU General Public License

public void saveRegionData(LoadedRegion loadedRegion) {
    MongoCollection<Document> collection = getDatabase().getCollection("chunks");

    Document regionDocument = new Document("_id", loadedRegion.getUniqueId().toString())
            .append("owner", loadedRegion.getOwner().toString())
            .append("world", loadedRegion.getWorld().getUniqueId().toString())
            .append("type", loadedRegion.getType().toString())
            .append("fromX", loadedRegion.getRegion().getFrom().getX())
            .append("fromZ", loadedRegion.getRegion().getFrom().getZ())
            .append("toX", loadedRegion.getRegion().getTo().getX())
            .append("toZ", loadedRegion.getRegion().getTo().getZ()).append("created", loadedRegion.getEpoch());

    collection.replaceOne(Filters.eq("_id", loadedRegion.getUniqueId().toString()), regionDocument,
            (new UpdateOptions()).upsert(true));
}

From source file:rocks.devonthe.stickychunk.database.MongodbDatabase.java

License:GNU General Public License

public void saveUserData(UserData userData) {
    MongoCollection<Document> collection = getDatabase().getCollection("users");

    Document userDocument = new Document("_id", userData.getUniqueId()).append("seen", userData.getLastSeen())
            .append("joined", userData.getUserJoined());

    collection.replaceOne(Filters.eq("_id", userData.getUniqueId().toString()), userDocument,
            (new UpdateOptions()).upsert(true));
}

From source file:stats.HangmanStats.java

License:Apache License

/**
 * Merges the database entries with the given dictionary to enhance the
 * dictionary. After merging the online database and the local one, the
 * local copy will be sorted by the amount that users used a word so that
 * most used words will be preffered./*from  ww  w .j  a  v  a 2 s  . c o  m*/
 *
 * @param dictionary The Dictionary to be merged
 * @param lang       The language requested
 */
public static void mergeWithDictionary(TabFile dictionary, Language lang) {
    FOKLogger.info(HangmanStats.class.getName(),
            "Merging offline dictionary for language " + lang.getLanguageCode() + " with online database...");
    MongoCollection<Document> coll = MongoSetup.getWordsUsedCollection();
    for (Document doc : coll.find(Filters.eq("lang", lang.getLanguageCode()))) {
        String word = doc.get("word").toString();
        int count = doc.getInteger("count");

        List<Integer> indexList = dictionary.indexOfIgnoreCase(word, 2);
        if (indexList.isEmpty()) {
            // Word not yet present in dictionary so add it
            dictionary.addRow(new String[] { "fromOnlineDatabase", lang.getLanguageCode() + ":lemma", word,
                    Integer.toString(count) });
        } else {
            dictionary.setValueAt(Integer.toString(count), indexList, 3);
        }
    }
    FOKLogger.info(HangmanStats.class.getName(), "Merge finished, sorting TabFile now...");

    dictionary.sortDescending(3);

    FOKLogger.info(HangmanStats.class.getName(), "Sorting finished.");
}

From source file:tour.Decimal128QuickTour.java

License:Apache License

/**
 * Run this main method to see the output of this quick example.
 *
 * @param args takes an optional single argument for the connection string
 *//*from  w  ww . j av  a2 s.  c  om*/
public static void main(final String[] args) {
    MongoClient mongoClient;

    if (args.length == 0) {
        // connect to the local database server
        mongoClient = new MongoClient();
    } else {
        mongoClient = new MongoClient(new MongoClientURI(args[0]));
    }

    // get handle to "mydb" database
    MongoDatabase database = mongoClient.getDatabase("mydb");

    // get a handle to the "test" collection
    MongoCollection<Document> collection = database.getCollection("test");

    // drop all the data in it
    collection.drop();

    // make a document and insert it
    Document doc = new Document("name", "MongoDB").append("amount1", Decimal128.parse(".10"))
            .append("amount2", new Decimal128(42L)).append("amount3", new Decimal128(new BigDecimal(".200")));

    collection.insertOne(doc);

    Document first = collection.find().filter(Filters.eq("amount1", new Decimal128(new BigDecimal(".10"))))
            .first();

    Decimal128 amount3 = (Decimal128) first.get("amount3");
    BigDecimal amount2AsBigDecimal = amount3.bigDecimalValue();

    System.out.println(amount3.toString());
    System.out.println(amount2AsBigDecimal.toString());

}

From source file:wasdev.sample.store.MongoDbVisitorStore.java

License:Apache License

@Override
public Visitor get(String name) {
    Document doc = collection.find(Filters.eq("_id", name)).first();
    Visitor visitor = new Visitor();
    visitor.set_id(doc.getObjectId("_id").toString());
    visitor.setName(doc.getString("name"));
    return visitor;
}

From source file:wasdev.sample.store.MongoDbVisitorStore.java

License:Apache License

@Override
public Visitor persist(Visitor td) {
    Document doc = new Document("name", td.getName()).append("count", 1);
    collection.insertOne(doc);//from w  w  w  .  ja  va 2s.  com
    doc = collection.find(Filters.eq("name", td.getName())).first();
    td.set_id(doc.getObjectId("_id").toString());
    return td;
}

From source file:wasdev.sample.store.MongoDbVisitorStore.java

License:Apache License

@Override
public Visitor update(String id, Visitor newVisitor) {
    collection.updateOne(Filters.eq("name", newVisitor.getName()),
            new Document("$set", new Document("name", newVisitor.getName()).append("count", 2)));

    Document myDoc = collection.find(Filters.eq("name", newVisitor.getName())).first();
    newVisitor.set_id(myDoc.getObjectId("_id").toString());
    return newVisitor;
}

From source file:wasdev.sample.store.MongoDbVisitorStore.java

License:Apache License

@Override
public void delete(String name) {
    collection.deleteOne(Filters.eq("name", name));
}