MongoUpdateQuery extends MongoInputQuery { @Override public void performQuery() { if (many) { if (options != null) { super.collection.updateMany(this.filters, this.update, this.options); } else { super.collection.updateMany(this.filters, this.update); } } else { if (options != null) { super.collection.updateOne(this.filters, this.update, this.options); } else { super.collection.updateOne(this.filters, this.update); } } } MongoUpdateQuery(MongoCollection collection, Bson filters, Bson update, boolean many, UpdateOptions options); @Override void performQuery();  }
@Test void performSingleInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("update_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); Document sample = sample(0); MongoInsertQuery insert = new MongoInsertQuery(collection, sample, null); insert.performQuery(); assertEquals(1, collection.count()); Bson filters = Filters.eq("updated", false); Bson doc = Updates.combine(Updates.set("updated", true)); MongoUpdateQuery updateQuery = new MongoUpdateQuery(collection, filters, doc, false, null); updateQuery.performQuery(); assertTrue(checkForNonUpdated(collection)); new MongoDeleteQuery(collection, new BsonDocument(), false, null).performQuery(); assertEquals(0, collection.count()); }
@Test void performSingleOptionInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("update_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); Document sample = sample(0); MongoInsertQuery query = new MongoInsertQuery(collection, sample, new InsertOneOptions()); query.performQuery(); assertEquals(1, collection.count()); Bson filters = Filters.eq("updated", false); Bson doc = Updates.combine(Updates.set("updated", true)); MongoUpdateQuery updateQuery = new MongoUpdateQuery(collection, filters, doc, false, new UpdateOptions()); updateQuery.performQuery(); assertTrue(checkForNonUpdated(collection)); new MongoDeleteQuery(collection, new BsonDocument(), false, new DeleteOptions()).performQuery(); assertEquals(0, collection.count()); }
@Test void performMultiInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("update_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); List<Document> samples = new ArrayList<>(); for (int i = 0; i < 100; i++) { samples.add(sample(i)); } MongoInsertQuery query = new MongoInsertQuery(collection, samples, null); query.performQuery(); assertEquals(100, collection.count()); Bson filters = Filters.eq("updated", false); Bson doc = Updates.combine(Updates.set("updated", true)); MongoUpdateQuery updateQuery = new MongoUpdateQuery(collection, filters, doc, true, null); updateQuery.performQuery(); assertTrue(checkForNonUpdated(collection)); new MongoDeleteQuery(collection, new BsonDocument(), true, null).performQuery(); assertEquals(0, collection.count()); }
@Test void performMultiOptionInsert() { MongoCollection<Document> collection = this.connector.getDatabase().getCollection("update_query"); collection.deleteMany(new BsonDocument()); assertEquals(0, collection.count()); List<Document> samples = new ArrayList<>(); for (int i = 0; i < 100; i++) { samples.add(sample(i)); } MongoInsertQuery query = new MongoInsertQuery(collection, samples, new InsertManyOptions()); query.performQuery(); assertEquals(100, collection.count()); Bson filters = Filters.eq("updated", false); Bson doc = Updates.combine(Updates.set("updated", true)); MongoUpdateQuery updateQuery = new MongoUpdateQuery(collection, filters, doc, true, new UpdateOptions()); updateQuery.performQuery(); assertTrue(checkForNonUpdated(collection)); new MongoDeleteQuery(collection, new BsonDocument(), true, new DeleteOptions()).performQuery(); assertEquals(0, collection.count()); }