@Override public Optional<T> call() throws Exception { @Nullable T result = collection().findOneAndDelete(convertToBson(criteria), options); return Optional.fromNullable(result); } });
public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindOneAndDeleteOptions opts = new FindOneAndDeleteOptions().sort(sort).projection(fields); collation.map(Collation::toMongoCollation).ifPresent(opts::collation); return collection.findOneAndDelete(query, opts); } }
@Signature public Document findOneAndDelete(BasicDBObject filter) { return (Document) getWrappedObject().findOneAndDelete(filter); }
public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindOneAndDeleteOptions opts = new FindOneAndDeleteOptions().sort(sort).projection(fields); collation.map(Collation::toMongoCollation).ifPresent(opts::collation); return collection.findOneAndDelete(query, opts); } }
@Override public Optional<T> call() throws Exception { @Nullable T result = collection().findOneAndDelete(convertToBson(criteria), options); return Optional.fromNullable(result); } });
/** * Finds a document and deletes it. * * @param query * The query * @return the removed object */ public T findAndRemove(Document query) { return mongoCollection.findOneAndDelete(serializeFields(query)); }
@Override public boolean delete(final RyaIRI subject) throws EntityStorageException { requireNonNull(subject); try { final Document deleted = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .findOneAndDelete( makeSubjectFilter(subject) ); return deleted != null; } catch(final MongoException e) { throw new EntityStorageException("Could not delete the Entity with Subject '" + subject.getData() + "'.", e); } }
@Override public boolean delete(final RyaURI typeId) throws TypeStorageException { requireNonNull(typeId); try { final Document deleted = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .findOneAndDelete( makeIdFilter(typeId) ); return deleted != null; } catch(final MongoException e) { throw new TypeStorageException("Could not delete the Type with ID '" + typeId.getData() + "'.", e); } }
@Override public boolean delete(final RyaURI subject) throws EntityStorageException { requireNonNull(subject); try { final Document deleted = mongo.getDatabase(ryaInstanceName) .getCollection(COLLECTION_NAME) .findOneAndDelete( makeSubjectFilter(subject) ); return deleted != null; } catch(final MongoException e) { throw new EntityStorageException("Could not delete the Entity with Subject '" + subject.getData() + "'.", e); } }
@Override public Optional<UserInfo> getUser(String token) { final Document document = systemUserCollection().findOneAndDelete(eq(ID_FIELD, token)); return document != null ? Optional.of(toUserInfo(document)) : Optional.empty(); }
@Override @Nullable public TDocument findOneAndDelete(@NotNull ClientSession clientSession, @NotNull Bson filter, @NotNull FindOneAndDeleteOptions options) { maybeThrowExceptionBeforeUpdate(); TDocument doc = collection.findOneAndDelete(clientSession, filter, options); maybeThrowExceptionAfterUpdate(); return doc; }
@Override @Nullable public TDocument findOneAndDelete(@NotNull Bson filter, @NotNull FindOneAndDeleteOptions options) { maybeThrowExceptionBeforeUpdate(); TDocument doc = collection.findOneAndDelete(filter, options); maybeThrowExceptionAfterUpdate(); return doc; }
@Override @Nullable public TDocument findOneAndDelete(@NotNull ClientSession clientSession, @NotNull Bson filter) { maybeThrowExceptionBeforeUpdate(); TDocument doc = collection.findOneAndDelete(clientSession, filter); maybeThrowExceptionAfterUpdate(); return doc; }
@Override @Nullable public TDocument findOneAndDelete(@NotNull Bson filter) { maybeThrowExceptionBeforeUpdate(); TDocument doc = collection.findOneAndDelete(filter); maybeThrowExceptionAfterUpdate(); return doc; }
@Override public <T extends IEntity> T delete(Class<T> entity, Serializable id) throws Exception { Document _document = __doGetCollection(entity).findOneAndDelete( Query.create(IMongo.OPT.ID, ComparisonExp.eq(new ObjectId(id.toString()))).toBson()); return ResultSetHelper.toEntity(entity, _document); }
@Test public void testFineOneAndUpdateRemove() { collection.insertOne(json("_id: 1, a: 1")); Document result = collection.findOneAndDelete(json("_id: 1")); assertThat(result).isEqualTo(json("_id: 1, a: 1")); assertThat(collection.countDocuments()).isZero(); }
@Test public void testFindAndRemoveFromEmbeddedList() { collection.insertOne(json("_id: 1, a: [1]")); Document result = collection.findOneAndDelete(json("_id: 1")); assertThat(result).isEqualTo(json("_id: 1, a: [1]")); assertThat(collection.countDocuments()).isZero(); }
@Override public boolean removeTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, TupleContext tupleContext) { Document toDelete = prepareIdObject( entityKey ); for ( String versionColumn : oldLockState.getColumnNames() ) { toDelete.put( versionColumn, oldLockState.get( versionColumn ) ); } MongoCollection<Document> collection = getCollection( entityKey ); Document deleted = collection.findOneAndDelete( toDelete ); return deleted != null; }
@Override public boolean removeTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, TupleContext tupleContext) { Document toDelete = prepareIdObject( entityKey ); for ( String versionColumn : oldLockState.getColumnNames() ) { toDelete.put( versionColumn, oldLockState.get( versionColumn ) ); } MongoCollection<Document> collection = getCollection( entityKey ); Document deleted = collection.findOneAndDelete( toDelete ); return deleted != null; }
@Override public void removeTuple(EntityKey key, TupleContext tupleContext) { Document toDelete = prepareIdObject( key ); WriteConcern writeConcern = getWriteConcern( tupleContext ); MongoCollection<Document> collection = getCollection( key ).withWriteConcern( writeConcern ); Document deleted = collection.findOneAndDelete( toDelete ); if ( deleted != null ) { provider.getBinaryStorageManager().removeEntityFromBinaryStorage( deleted, key.getMetadata() ); } }