@Override public void delete(final String id) { sessions.deleteOne(new Document("_id", id)); }
private boolean deleteTableMetadata(SchemaTableName schemaTableName) { String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); MongoDatabase db = client.getDatabase(schemaName); if (!collectionExists(db, tableName)) { return false; } DeleteResult result = db.getCollection(schemaCollection) .deleteOne(new Document(TABLE_NAME_KEY, tableName)); return result.getDeletedCount() == 1; }
/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See the {@link DB} * class's description for a discussion of error codes. */ @Override public Status delete(String table, String key) { try { MongoCollection<Document> collection = database.getCollection(table); Document query = new Document("_id", key); DeleteResult result = collection.withWriteConcern(writeConcern).deleteOne(query); if (result.wasAcknowledged() && result.getDeletedCount() == 0) { System.err.println("Nothing deleted for key " + key); return Status.NOT_FOUND; } return Status.OK; } catch (Exception e) { System.err.println(e.toString()); return Status.ERROR; } }
@Signature public boolean deleteOne(BasicDBObject filter) { DeleteResult result = getWrappedObject().deleteOne(filter); return result.getDeletedCount() > 0; }
collection.deleteOne(eq("_id", id));
public void deleteTransaction(TransactionArchive archive) { try { TransactionXid transactionXid = (TransactionXid) archive.getXid(); byte[] global = transactionXid.getGlobalTransactionId(); String identifier = ByteUtils.byteArrayToString(global); String application = CommonUtils.getApplication(this.endpoint); String databaseName = application.replaceAll("\\W", "_"); MongoDatabase mdb = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> transactions = mdb.getCollection(CONSTANTS_TB_TRANSACTIONS); DeleteResult result = transactions.deleteOne(Filters.eq(CONSTANTS_FD_GLOBAL, identifier)); if (result.getDeletedCount() != 1) { logger.error("Error occurred while deleting transaction(deleted= {}).", result.getDeletedCount()); } } catch (RuntimeException error) { logger.error("Error occurred while deleting transaction!", error); } }
public void unlockTransactionInMongoDB(TransactionXid transactionXid, String identifier) { byte[] global = transactionXid.getGlobalTransactionId(); String instanceId = ByteUtils.byteArrayToString(global); try { String application = CommonUtils.getApplication(this.endpoint); String databaseName = application.replaceAll("\\W", "_"); MongoDatabase mdb = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> collection = mdb.getCollection(CONSTANTS_TB_LOCKS); Bson globalFilter = Filters.eq(CONSTANTS_FD_GLOBAL, instanceId); Bson instIdFilter = Filters.eq("identifier", identifier); DeleteResult result = collection.deleteOne(Filters.and(globalFilter, instIdFilter)); if (result.getDeletedCount() == 0) { logger.warn("Error occurred while unlocking transaction(gxid= {}).", instanceId); } } catch (RuntimeException rex) { logger.error("Error occurred while unlocking transaction(gxid= {})!", instanceId, rex); } }
private void executeDelete(@Nullable final ClientSession clientSession, final BsonValue id) { DeleteResult result; if (clientSession != null) { result = filesCollection.deleteOne(clientSession, new BsonDocument("_id", id)); chunksCollection.deleteMany(clientSession, new BsonDocument("files_id", id)); } else { result = filesCollection.deleteOne(new BsonDocument("_id", id)); chunksCollection.deleteMany(new BsonDocument("files_id", id)); } if (result.wasAcknowledged() && result.getDeletedCount() == 0) { throw new MongoGridFSException(format("No file found with the id: %s", id)); } }
Bson branchFilter = Filters.eq(CONSTANTS_FD_BRANCH, ByteUtils.byteArrayToString(branch)); collection.deleteOne(Filters.and(globalFilter, branchFilter));
result = collection.deleteOne(query); } else { result = collection.deleteMany(query);
: collection.deleteOne(removeQuery, options);
@Override public void delete(String sessionId) { this.sessions.deleteOne(eq(SESSION_ID, sessionId)); }
@Test @FixFor("DBZ-563") public void shouldDropTombstoneByDefault() throws InterruptedException { // First insert primary().execute("insert", client -> { client.getDatabase(DB_NAME).getCollection(this.getCollectionName()) .insertOne(Document.parse("{'_id': 1, 'dataStr': 'hello', 'dataInt': 123, 'dataLong': 80000000000}")); }); SourceRecords records = consumeRecordsByTopic(1); assertThat(records.recordsForTopic(this.topicName()).size()).isEqualTo(1); // Test Delete primary().execute("delete", client -> { client.getDatabase(DB_NAME).getCollection(this.getCollectionName()).deleteOne(RawBsonDocument.parse("{'_id' : 1}")); }); // First delete record to arrive is coming from the oplog SourceRecord firstRecord = getRecordByOperation(Envelope.Operation.DELETE); final SourceRecord transformedDelete = transformation.apply(firstRecord); assertThat(transformedDelete).isNull(); // Second record is the tombstone SourceRecord tombstoneRecord = getNextRecord(); assertThat(tombstoneRecord).isNotNull(); // Test tombstone record is dropped final SourceRecord transformedTombstone = transformation.apply(tombstoneRecord); assertThat(transformedTombstone).isNull(); }
contacts.deleteOne(Filters.eq("name", "Jon Snow")); Testing.debug("Removed the Jon Snow document from 'dbA.contacts' collection"); });
public void delete(ServerConfiguration configuration, final MongoCollection mongoCollection, final Object _id) { Task task = mongoClient -> { MongoDatabase mongoDatabase = mongoCollection.getParentDatabase(); com.mongodb.client.MongoDatabase database = mongoClient.getDatabase(mongoDatabase.getName()); com.mongodb.client.MongoCollection<Document> collection = database.getCollection(mongoCollection.getName()); collection.deleteOne(new Document("_id", _id)); }; executeTask(configuration, task); }
: collection.deleteOne(removeQuery, options);
/** {@inheritDoc} */ @Override public void delete(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } getFeaturesCollection().deleteOne(BUILDER.getFeatUid(uid)); }
/** {@inheritDoc} */ public void deleteProperty(String name) { assertPropertyExist(name); getPropertiesCollection().deleteOne(BUILDER.getName(name)); }
private <T> OpResult removeObject(MongoCollection<Document> collection, String nameField, String name) { BsonDocument filter = new BsonDocument(); filter.append(nameField, new BsonString(name)); DeleteResult dr = collection.deleteOne(filter); OpResult result = new OpResult(); result.code = 200; result.message = String.format(" %d config item removed!", dr.getDeletedCount()); return result; }
@NotNull @Override public DeleteResult deleteOne(@NotNull Bson filter, @NotNull DeleteOptions options) { maybeThrowExceptionBeforeUpdate(); DeleteResult result = collection.deleteOne(filter, options); maybeThrowExceptionAfterUpdate(); return result; }