Search in sources :

Example 6 with Document

use of org.bson.Document in project mongo-java-driver by mongodb.

the class ClusterFixture method enableMaxTimeFailPoint.

public static void enableMaxTimeFailPoint() {
    assumeThat(isSharded(), is(false));
    new CommandWriteOperation<BsonDocument>("admin", new BsonDocumentWrapper<Document>(new Document("configureFailPoint", "maxTimeAlwaysTimeOut").append("mode", "alwaysOn"), new DocumentCodec()), new BsonDocumentCodec()).execute(getBinding());
}
Also used : BsonDocument(org.bson.BsonDocument) DocumentCodec(org.bson.codecs.DocumentCodec) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonDocumentWrapper(org.bson.BsonDocumentWrapper) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Example 7 with Document

use of org.bson.Document in project mongo-java-driver by mongodb.

the class ClusterFixture method isEnterpriseServer.

@SuppressWarnings("unchecked")
public static boolean isEnterpriseServer() {
    Document buildInfo = getBuildInfo();
    List<String> modules = Collections.emptyList();
    if (buildInfo.containsKey("modules")) {
        modules = (List<String>) buildInfo.get("modules");
    }
    return modules.contains("enterprise");
}
Also used : Document(org.bson.Document) BsonDocument(org.bson.BsonDocument)

Example 8 with Document

use of org.bson.Document in project mongo-java-driver by mongodb.

the class UpdatePrimer method replaceDocument.

@Test
public void replaceDocument() {
    assumeTrue(serverVersionAtLeast(2, 6));
    // @begin: replace-document
    // @code: start
    db.getCollection("restaurants").replaceOne(new Document("restaurant_id", "41704620"), new Document("address", new Document().append("street", "2 Avenue").append("zipcode", "10075").append("building", "1480").append("coord", asList(-73.9557413, 40.7720266))).append("name", "Vella 2"));
// @code: end
/*
       // @post: start
           The replaceOne operation returns a ``UpdateResult`` which contains information about the operation.
           The ``getModifiedCount`` method returns the number of documents modified.
       // @post: end
       */
// @end: replace-document
}
Also used : Document(org.bson.Document) Test(org.junit.Test)

Example 9 with Document

use of org.bson.Document in project mongo-java-driver by mongodb.

the class GridFSBucketImpl method getFileByName.

private GridFSFile getFileByName(final String filename, final GridFSDownloadOptions options) {
    int revision = options.getRevision();
    int skip;
    int sort;
    if (revision >= 0) {
        skip = revision;
        sort = 1;
    } else {
        skip = (-revision) - 1;
        sort = -1;
    }
    GridFSFile fileInfo = find(new Document("filename", filename)).skip(skip).sort(new Document("uploadDate", sort)).first();
    if (fileInfo == null) {
        throw new MongoGridFSException(format("No file found with the filename: %s and revision: %s", filename, revision));
    }
    return fileInfo;
}
Also used : GridFSFile(com.mongodb.client.gridfs.model.GridFSFile) MongoGridFSException(com.mongodb.MongoGridFSException) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument)

Example 10 with Document

use of org.bson.Document in project mongo-java-driver by mongodb.

the class GridFSBucketImpl method checkCreateIndex.

private void checkCreateIndex() {
    if (!checkedIndexes) {
        if (filesCollection.withDocumentClass(Document.class).withReadPreference(primary()).find().projection(new Document("_id", 1)).first() == null) {
            Document filesIndex = new Document("filename", 1).append("uploadDate", 1);
            if (!hasIndex(filesCollection.withReadPreference(primary()), filesIndex)) {
                filesCollection.createIndex(filesIndex);
            }
            Document chunksIndex = new Document("files_id", 1).append("n", 1);
            if (!hasIndex(chunksCollection.withReadPreference(primary()), chunksIndex)) {
                chunksCollection.createIndex(chunksIndex, new IndexOptions().unique(true));
            }
        }
        checkedIndexes = true;
    }
}
Also used : IndexOptions(com.mongodb.client.model.IndexOptions) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument)

Aggregations

Document (org.bson.Document)2386 Test (org.junit.jupiter.api.Test)900 Test (org.junit.Test)472 ArrayList (java.util.ArrayList)209 BsonDocument (org.bson.BsonDocument)188 List (java.util.List)160 Bson (org.bson.conversions.Bson)133 MongoDatabase (com.mongodb.client.MongoDatabase)119 Update (org.springframework.data.mongodb.core.query.Update)116 ObjectId (org.bson.types.ObjectId)113 Map (java.util.Map)92 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)83 Test (org.testng.annotations.Test)82 HashMap (java.util.HashMap)79 BasicDBObject (com.mongodb.BasicDBObject)75 Query (org.springframework.data.mongodb.core.query.Query)67 MongoCollection (com.mongodb.client.MongoCollection)54 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)50 MongoClient (com.mongodb.MongoClient)48 Date (java.util.Date)47