Search in sources :

Example 51 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project zeppelin by apache.

the class MongoNotebookRepo method saveNote.

private void saveNote(Note note) {
    Document doc = noteToDocument(note);
    notes.replaceOne(eq(Fields.ID, note.getId()), doc, new UpdateOptions().upsert(true));
}
Also used : Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions)

Example 52 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project zeppelin by apache.

the class MongoNotebookRepo method completeFolder.

/**
 * create until parent folder if not exists.
 *
 * @param splitPath path to completed.
 * @return direct parent folder id
 */
private String completeFolder(String[] splitPath) {
    String pId = "0";
    for (String currentPath : splitPath) {
        Document query = new Document(Fields.PID, pId).append(Fields.IS_DIR, true).append(Fields.NAME, currentPath);
        String cId = new ObjectId().toString();
        Document doc = new Document("$setOnInsert", new Document(Fields.ID, cId).append(Fields.PID, pId).append(Fields.IS_DIR, true).append(Fields.NAME, currentPath));
        Document exist = folders.find(query).first();
        if (exist == null) {
            folders.updateOne(query, doc, new UpdateOptions().upsert(true));
            pId = cId;
        } else {
            pId = exist.getString(Fields.ID);
        }
    }
    return pId;
}
Also used : ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions)

Example 53 with UpdateOptions

use of com.mongodb.client.model.UpdateOptions in project zeppelin by apache.

the class MongoNotebookRepo method saveNotePath.

/**
 * save note to path.
 *
 * @param noteId note id
 * @param pId    note parent folder id
 */
private void saveNotePath(String noteId, String noteName, String pId) {
    Document filter = new Document(Fields.ID, noteId);
    Document doc = new Document(Fields.ID, noteId).append(Fields.PID, pId).append(Fields.IS_DIR, false).append(Fields.NAME, noteName);
    folders.replaceOne(filter, doc, new UpdateOptions().upsert(true));
}
Also used : Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions)

Aggregations

UpdateOptions (com.mongodb.client.model.UpdateOptions)53 Document (org.bson.Document)31 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)21 Bson (org.bson.conversions.Bson)17 UpdateResult (com.mongodb.client.result.UpdateResult)10 Test (org.junit.jupiter.api.Test)10 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)8 ArrayList (java.util.ArrayList)6 BsonDocument (org.bson.BsonDocument)6 Test (org.junit.Test)6 Update (org.springframework.data.mongodb.core.query.Update)4 BasicDBObject (com.mongodb.BasicDBObject)3 MongoCollection (com.mongodb.client.MongoCollection)3 CountOptions (com.mongodb.client.model.CountOptions)3 IOException (java.io.IOException)3 List (java.util.List)3 BsonValue (org.bson.BsonValue)3 ObjectId (org.bson.types.ObjectId)3 MongodbException (com.duangframework.core.exceptions.MongodbException)2 Block (com.mongodb.Block)2