Search in sources :

Example 46 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project serverless by bluenimble.

the class MongoDatabaseImpl method delete.

@Override
public int delete(String eType, Object id) throws DatabaseException {
    checkNotNull(eType);
    if (id == null) {
        throw new DatabaseException("can't delete object (missing object id)");
    }
    MongoCollection<Document> collection = db.getCollection(eType);
    if (collection == null) {
        return 0;
    }
    DeleteResult result = collection.deleteOne(eq(DatabaseObjectImpl.ObjectIdKey, new ObjectId(String.valueOf(id))));
    return (int) result.getDeletedCount();
}
Also used : ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) DatabaseException(com.bluenimble.platform.db.DatabaseException) DeleteResult(com.mongodb.client.result.DeleteResult)

Aggregations

DeleteResult (com.mongodb.client.result.DeleteResult)46 Document (org.bson.Document)20 UpdateResult (com.mongodb.client.result.UpdateResult)10 BsonDocument (org.bson.BsonDocument)9 Test (org.junit.jupiter.api.Test)9 BasicDBObject (com.mongodb.BasicDBObject)7 WriteConcern (com.mongodb.WriteConcern)6 Bson (org.bson.conversions.Bson)6 MongoException (com.mongodb.MongoException)5 ArrayList (java.util.ArrayList)5 DataAccessException (org.springframework.dao.DataAccessException)5 MongoGridFSException (com.mongodb.MongoGridFSException)4 MongoClient (com.mongodb.client.MongoClient)4 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)4 ReadPreference (com.mongodb.ReadPreference)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 InsertOneResult (com.mongodb.client.result.InsertOneResult)3 MongoClient (com.mongodb.reactivestreams.client.MongoClient)3 MongoDatabase (com.mongodb.reactivestreams.client.MongoDatabase)3 ObjectId (org.bson.types.ObjectId)3