MongoDeleteQuery extends MongoInputQuery { @Override public void performQuery() { if (this.many) { if (this.options != null) { super.collection.deleteMany(this.bson, this.options); } else { super.collection.deleteMany(this.bson); } } else { if (this.options != null) { super.collection.deleteOne(this.bson, this.options); } else { super.collection.deleteOne(this.bson); } } } MongoDeleteQuery(MongoCollection collection, Bson bson, boolean many, DeleteOptions options); @Override void performQuery();  }
@Test void performSingleInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("delete_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); Document sample = new Document(); sample.put("id", 0); MongoInsertQuery insert = new MongoInsertQuery(collection, sample, null); insert.performQuery(); assertEquals(1, collection.count()); new MongoDeleteQuery(collection, new BsonDocument(), false, null).performQuery(); assertEquals(0, collection.count()); }
@Test void performSingleOptionInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("delete_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); Document sample = new Document(); sample.put("id", 0); MongoInsertQuery query = new MongoInsertQuery(collection, sample, new InsertOneOptions()); query.performQuery(); assertEquals(1, collection.count()); new MongoDeleteQuery(collection, new BsonDocument(), false, new DeleteOptions()).performQuery(); assertEquals(0, collection.count()); }
@Test void performMultiInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("delete_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); List<Document> samples = new ArrayList<>(); for (int i = 0; i < 100; i++) { Document sample = new Document(); sample.put("id", i); samples.add(sample); } MongoInsertQuery query = new MongoInsertQuery(collection, samples, null); query.performQuery(); assertEquals(100, collection.count()); new MongoDeleteQuery(collection, new BsonDocument(), true, null).performQuery(); assertEquals(0, collection.count()); }
@Test void performMultiOptionInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("delete_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); List<Document> samples = new ArrayList<>(); for (int i = 0; i < 100; i++) { Document sample = new Document(); sample.put("id", i); samples.add(sample); } MongoInsertQuery query = new MongoInsertQuery(collection, samples, new InsertManyOptions()); query.performQuery(); assertEquals(100, collection.count()); new MongoDeleteQuery(collection, new BsonDocument(), true, new DeleteOptions()).performQuery(); assertEquals(0, collection.count()); }