private BsonDocument getQuery(BsonValue<?> value) throws BadValueException { if (!(value instanceof BsonDocument)) { throw new BadValueException("Unknown top level operator: $query"); } return (BsonDocument) value; }
@Nullable private BsonDocument getHint(BsonValue<?> value) throws BadValueException { if (value instanceof BsonDocument) { return (BsonDocument) value; } if (value instanceof BsonString) { return new SingleEntryBsonDocument(((BsonString) value).getValue(), PrimitiveBsonDouble .newInstance(1)); } throw new BadValueException("$hint must be either a string or a nested object"); }
/** * Confirms that the given bson document only contains fields whose names given. * * @param objectName the container's name, that will be included in the error messages * @param bson the document whose fields are going to be checked * @param fields the fields we are going to accept * @throws BadValueException if an unexpected field is found */ public static void checkOnlyHasFields( String objectName, BsonDocument bson, Set<String> fields) throws BadValueException { for (Entry<?> entry : bson) { if (!fields.contains(entry.getKey())) { throw new BadValueException( "Unexpected field " + entry.getKey() + " in " + objectName ); } } }
@Override public void asyncDelete( String database, String collection, boolean singleRemove, BsonDocument selector) throws MongoException { try { MongoCollection<BsonDocument> collectionObject = owner.getDriverClient() .getDatabase(database) .getCollection(collection, BsonDocument.class); org.bson.BsonDocument mongoSelector = MongoBsonTranslator.translate(selector); if (singleRemove) { collectionObject.deleteOne(mongoSelector); } else { collectionObject.deleteMany(mongoSelector); } } catch (com.mongodb.MongoException ex) { //a general Mongo driver exception if (ErrorCode.isErrorCode(ex.getCode())) { throw toMongoException(ex); } else { throw toRuntimeMongoException(ex); } } catch (IOException ex) { throw new BadValueException("Unexpected IO exception", ex); } }
throw new BadValueException("Unexpected IO exception", ex);
throw new BadValueException("Unexpected IO exception", ex);