├── .gitattributes ├── src └── beaniecocktails │ ├── scripts │ ├── __init__.py │ └── init_db.py │ ├── models.py │ ├── __init__.py │ └── routes.py ├── Justfile ├── sample_data └── hunters_moon.json ├── pyproject.toml ├── README.md ├── .gitignore └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /src/beaniecocktails/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # This package is intended to contain various scripts for interacting with the application. 2 | -------------------------------------------------------------------------------- /Justfile: -------------------------------------------------------------------------------- 1 | run: 2 | python -m uvicorn --reload beaniecocktails:app 3 | 4 | check: 5 | python -m ruff check 6 | 7 | clean: 8 | rm -rf build dist src/*.egg-info .tox .pytest_cache pip-wheel-metadata .DS_Store 9 | find src -name '__pycache__' | xargs rm -rf 10 | 11 | install: 12 | python -m pip install -e . 13 | 14 | dev: 15 | python -m pip install -e .[dev] 16 | -------------------------------------------------------------------------------- /src/beaniecocktails/models.py: -------------------------------------------------------------------------------- 1 | from typing import Optional, List 2 | 3 | from beanie import Document 4 | from pydantic import BaseModel, Field 5 | 6 | 7 | class Cocktail(Document): 8 | 9 | class Settings: 10 | name = "recipes" 11 | 12 | name: str 13 | ingredients: List["Ingredient"] 14 | instructions: List[str] 15 | 16 | 17 | class Ingredient(BaseModel): 18 | name: str 19 | quantity: Optional["IngredientQuantity"] 20 | 21 | 22 | class IngredientQuantity(BaseModel): 23 | quantity: Optional[str] 24 | unit: Optional[str] 25 | 26 | 27 | class IngredientAggregation(BaseModel): 28 | """ A model for an ingredient count. """ 29 | 30 | id: str = Field(None, alias="_id") 31 | total: int 32 | 33 | 34 | # Cocktail.update_forward_refs() 35 | # Ingredient.update_forward_refs() 36 | -------------------------------------------------------------------------------- /sample_data/hunters_moon.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Hunter's Moon", 3 | "ingredients": [ 4 | { 5 | "name": "Vermouth", 6 | "quantity": { 7 | "quantity": "25", 8 | "unit": "ml" 9 | } 10 | }, 11 | { 12 | "name": "Maraschino Cherry", 13 | "quantity": { 14 | "quantity": "15", 15 | "unit": "ml" 16 | } 17 | }, 18 | { 19 | "name": "Sugar Syrup", 20 | "quantity": { 21 | "quantity": "10", 22 | "unit": "ml" 23 | } 24 | }, 25 | { 26 | "name": "Lemonade", 27 | "quantity": { 28 | "quantity": "100", 29 | "unit": "ml" 30 | } 31 | }, 32 | { 33 | "name": "Blackberries", 34 | "quantity": { 35 | "quantity": "2", 36 | "unit": "items" 37 | } 38 | } 39 | ], 40 | "instructions": ["Add all the ingredients.", "Shake with ice.", "Serve with a cherry on top."] 41 | } 42 | -------------------------------------------------------------------------------- /src/beaniecocktails/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | beaniecocktails - A cocktail API built with MongoDB and Beanie 3 | """ 4 | 5 | 6 | from motor.motor_asyncio import AsyncIOMotorClient 7 | from beanie import init_beanie 8 | from fastapi import FastAPI 9 | from pydantic_settings import BaseSettings 10 | 11 | from .models import Cocktail 12 | from .routes import cocktail_router 13 | 14 | 15 | async def app_lifespan(app: FastAPI): 16 | # startup code goes here: 17 | client: AsyncIOMotorClient = AsyncIOMotorClient( 18 | Settings().mongodb_url, 19 | connectTimeoutMS=1000, 20 | socketTimeoutMS=1000, 21 | serverSelectionTimeoutMS=1000, 22 | ) 23 | await init_beanie(client.get_default_database(), document_models=[Cocktail]) 24 | app.include_router(cocktail_router, prefix="/v1") 25 | 26 | yield 27 | 28 | # shutdown code goes here: 29 | client.close() 30 | 31 | 32 | app = FastAPI(lifespan=app_lifespan) 33 | 34 | 35 | class Settings(BaseSettings): 36 | mongodb_url: str = "mongodb://localhost:27017/cocktails" 37 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [tool.hatch.build.targets.wheel] 6 | packages = ["src/beaniecocktails"] 7 | 8 | [project] 9 | name = "beanie-cocktails" 10 | version = "0.0.1" 11 | authors = [ 12 | { name="Mark Smith", email="mark.smith@mongodb.com" }, 13 | ] 14 | description = "A small example package" 15 | readme = "README.md" 16 | requires-python = ">=3.8" 17 | classifiers = [ 18 | "Programming Language :: Python :: 3", 19 | "License :: OSI Approved :: Apache Software License", 20 | "Operating System :: OS Independent", 21 | ] 22 | dependencies = [ 23 | "beanie ~=1.26.0", 24 | "fastapi ~=0.114.0", 25 | "motor ~=3.5.1", 26 | "pydantic ~=2.9.1", 27 | "pydantic-settings ~=2.4.0", 28 | "tqdm ~=4.66.5", 29 | "uvicorn", 30 | ] 31 | keywords = [ 32 | "fastapi", "beanie", "mongodb", "example", 33 | ] 34 | 35 | [project.optional-dependencies] 36 | tests = [ 37 | "coverage[toml]~=5.0.2", 38 | "pytest", 39 | ] 40 | dev = [ 41 | "ruff", 42 | ] 43 | 44 | [project.urls] 45 | Homepage = "https://github.com/mongodb-developer/beanie-example" 46 | Issues = "https://github.com/mongodb-developer/beanie-example/issues" 47 | 48 | [project.scripts] 49 | init-db = "beaniecocktails.scripts.init_db:main" 50 | 51 | [tool.coverage.run] 52 | parallel = true 53 | branch = true 54 | source = ["beaniecocktails"] 55 | 56 | [tool.coverage.paths] 57 | source = ["src", ".tox/*/site-packages"] 58 | 59 | [tool.coverage.report] 60 | show_missing = true 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building a Cocktail API with Beanie! 2 | 3 | This is a sample cocktail API built with [MongoDB](https://www.mongodb.com/company/what-is-mongodb), 4 | [Beanie](https://beanie-odm.dev/), 5 | and [FastAPI](https://fastapi.tiangolo.com/). 6 | 7 | This code was written to try out Beanie and was used to write a [blog post](https://developer.mongodb.com/article/beanie-odm-fastapi-cocktails/), 8 | which may be more interesting than this code. 9 | 10 | ## Install It 11 | 12 | Run the following to install the project (and dev dependencies) into your active virtualenv: 13 | 14 | ```bash 15 | python -m pip install -e .[dev] 16 | ``` 17 | 18 | ## Initialize Your Database 19 | 20 | The previous step installs a script, `init-db`, that will generate some random 21 | cocktails for you, if you want: 22 | 23 | ```bash 24 | # This will create 100 dummy cocktails in your database 25 | # (or run without --dummy-data to just initialize indexes.): 26 | export MONGODB_URL="mongodb+srv://:@host/database" 27 | init-db --dummy-data 28 | ``` 29 | 30 | > **Don't consume any of the cocktails this script generates, they're randomly generated! 31 | 32 | 33 | ## Run It 34 | 35 | If you have an Atlas database you can run the server with: 36 | 37 | ```bash 38 | export MONGODB_URL="mongodb+srv://:@host/database" 39 | uvicorn beaniecocktails:app --reload 40 | ``` 41 | 42 | You should then be able to view your API docs at http://127.0.0.1:8000/docs/ 43 | 44 | > **Note:** This app will only work on MongoDB Atlas clusters, because it makes use of [Atlas Search](https://docs.atlas.mongodb.com/atlas-search/). 45 | 46 | ## Feedback 47 | 48 | I'd love to know whether you found this useful, or if you had any problems. 49 | Please leave feedback on the [MongoDB Community Forums](https://developer.mongodb.com/community/forums/) and tag me `@Mark_Smith`. -------------------------------------------------------------------------------- /src/beaniecocktails/routes.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from fastapi import APIRouter, HTTPException, Depends 4 | from beanie import PydanticObjectId 5 | 6 | from .models import Cocktail, IngredientAggregation 7 | 8 | cocktail_router = APIRouter() 9 | 10 | 11 | async def get_cocktail(cocktail_id: PydanticObjectId) -> Cocktail: 12 | """ Helper function to look up a cocktail by id """ 13 | 14 | cocktail = await Cocktail.get(cocktail_id) 15 | if cocktail is None: 16 | raise HTTPException(status_code=404, detail="Cocktail not found") 17 | return cocktail 18 | 19 | 20 | @cocktail_router.get("/cocktails/{cocktail_id}", response_model=Cocktail) 21 | async def get_cocktail_by_id(cocktail: Cocktail = Depends(get_cocktail)): 22 | return cocktail 23 | 24 | 25 | @cocktail_router.get("/cocktails/", response_model=List[Cocktail]) 26 | async def list_cocktails(): 27 | return await Cocktail.find_all().to_list() 28 | 29 | 30 | @cocktail_router.post("/cocktails/", response_model=Cocktail) 31 | async def create_cocktail(cocktail: Cocktail): 32 | return await cocktail.create() 33 | 34 | 35 | @cocktail_router.get("/ingredients", response_model=List[IngredientAggregation]) 36 | async def list_ingredients(): 37 | """ Group on each ingredient name and return a list of `IngredientAggregation`s. """ 38 | 39 | return await Cocktail.aggregate( 40 | aggregation_pipeline=[ 41 | {"$unwind": "$ingredients"}, 42 | {"$group": {"_id": "$ingredients.name", "total": {"$sum": 1}}}, 43 | {"$sort": {"_id": 1}}, 44 | ], 45 | projection_model=IngredientAggregation, 46 | ).to_list() 47 | 48 | 49 | @cocktail_router.get("/cocktail_autocomplete", response_model=List[str]) 50 | async def cocktail_autocomplete(fragment: str): 51 | """ Return an array of cocktail names matched from a string fragment. """ 52 | 53 | return [ 54 | c["name"] 55 | for c in await Cocktail.aggregate( 56 | aggregation_pipeline=[ 57 | { 58 | "$search": { 59 | "autocomplete": { 60 | "query": fragment, 61 | "path": "name", 62 | } 63 | } 64 | } 65 | ] 66 | ).to_list() 67 | ] 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/python,osx,windows 3 | # Edit at https://www.gitignore.io/?templates=python,osx,windows 4 | 5 | ### OSX ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | ### Python ### 34 | # Byte-compiled / optimized / DLL files 35 | __pycache__/ 36 | *.py[cod] 37 | *$py.class 38 | 39 | # C extensions 40 | *.so 41 | 42 | # Distribution / packaging 43 | .Python 44 | build/ 45 | develop-eggs/ 46 | dist/ 47 | downloads/ 48 | eggs/ 49 | .eggs/ 50 | lib/ 51 | lib64/ 52 | parts/ 53 | sdist/ 54 | var/ 55 | wheels/ 56 | pip-wheel-metadata/ 57 | share/python-wheels/ 58 | *.egg-info/ 59 | .installed.cfg 60 | *.egg 61 | MANIFEST 62 | 63 | # PyInstaller 64 | # Usually these files are written by a python script from a template 65 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 66 | *.manifest 67 | *.spec 68 | 69 | # Installer logs 70 | pip-log.txt 71 | pip-delete-this-directory.txt 72 | 73 | # Unit test / coverage reports 74 | htmlcov/ 75 | .tox/ 76 | .nox/ 77 | .coverage 78 | .coverage.* 79 | .cache 80 | nosetests.xml 81 | coverage.xml 82 | *.cover 83 | .hypothesis/ 84 | .pytest_cache/ 85 | 86 | # Translations 87 | *.mo 88 | *.pot 89 | 90 | # Scrapy stuff: 91 | .scrapy 92 | 93 | # Sphinx documentation 94 | docs/_build/ 95 | 96 | # PyBuilder 97 | target/ 98 | 99 | # pyenv 100 | .python-version 101 | 102 | # pipenv 103 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 104 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 105 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 106 | # install all needed dependencies. 107 | #Pipfile.lock 108 | 109 | # celery beat schedule file 110 | celerybeat-schedule 111 | 112 | # SageMath parsed files 113 | *.sage.py 114 | 115 | # Spyder project settings 116 | .spyderproject 117 | .spyproject 118 | 119 | # Rope project settings 120 | .ropeproject 121 | 122 | # Mr Developer 123 | .mr.developer.cfg 124 | .project 125 | .pydevproject 126 | 127 | # mkdocs documentation 128 | /site 129 | 130 | # mypy 131 | .mypy_cache/ 132 | .dmypy.json 133 | dmypy.json 134 | 135 | # Pyre type checker 136 | .pyre/ 137 | 138 | ### Windows ### 139 | # Windows thumbnail cache files 140 | Thumbs.db 141 | Thumbs.db:encryptable 142 | ehthumbs.db 143 | ehthumbs_vista.db 144 | 145 | # Dump file 146 | *.stackdump 147 | 148 | # Folder config file 149 | [Dd]esktop.ini 150 | 151 | # Recycle Bin used on file shares 152 | $RECYCLE.BIN/ 153 | 154 | # Windows Installer files 155 | *.cab 156 | *.msi 157 | *.msix 158 | *.msm 159 | *.msp 160 | 161 | # Windows shortcuts 162 | *.lnk 163 | 164 | # End of https://www.gitignore.io/api/python,osx,windows 165 | 166 | venv 167 | .env 168 | .envrc -------------------------------------------------------------------------------- /src/beaniecocktails/scripts/init_db.py: -------------------------------------------------------------------------------- 1 | """ 2 | init-db - A crude script to generate some sample cocktail data. 3 | 4 | (This must be run from the project root, 5 | otherwise it won't be able to load seed cocktail file, "hunters_moon.json") 6 | """ 7 | 8 | from argparse import ArgumentParser 9 | import asyncio 10 | from pathlib import Path 11 | from random import randint 12 | import sys 13 | 14 | from beanie import init_beanie 15 | from motor.motor_asyncio import AsyncIOMotorClient 16 | from tqdm import tqdm 17 | 18 | from beaniecocktails import Settings 19 | from beaniecocktails.models import Cocktail 20 | 21 | COCKTAIL_NAMES = [ 22 | "Basil Gimlet", 23 | "Black Russian", 24 | "Blackberry Bourbon Smash", 25 | "Blood and Sand", 26 | "Blue Hawaiian", 27 | "Blue Lagoon", 28 | "Bourbon Street", 29 | "Caipirinha", 30 | "Champagne Cocktail", 31 | "Classic Daiquiri", 32 | "Classic Gin and Tonic", 33 | "Classic Mojito", 34 | "Cognac Old Fashioned", 35 | "Corpse Reviver #2", 36 | "Cucumber Collins", 37 | "Cucumber Gimlet", 38 | "Dark 'N' Stormy", 39 | "El Diablo", 40 | "Espresso Con Panna", 41 | "French 75", 42 | "French Connection", 43 | "Gin Fizz", 44 | "Golden Bee", 45 | "Grapefruit Basil Martini", 46 | "Green Fairy", 47 | "Hemingway Daiquiri", 48 | "Hemingway Special", 49 | "Irish Coffee", 50 | "Irish Mule", 51 | "Julep", 52 | "Lemon Drop", 53 | "Lillet Spritz", 54 | "Midnight Express", 55 | "Old Fashioned", 56 | "Peach Bellini", 57 | "Pear-fect Punch", 58 | "Penicillin", 59 | "Pimm's Cup", 60 | "Pomegranate Martini", 61 | "Sakura Spritz", 62 | "Scorpion's Tail", 63 | "Shirley Temple", 64 | "Sloe Gin Fizz", 65 | "Smoky Sour", 66 | "Sour Cherry", 67 | "Southern Belle", 68 | "Spicy Mango Mule", 69 | "Spiked Apple Cider", 70 | "Tequila Sunrise (Frozen)", 71 | "Tequila Sunrise (Regular)", 72 | "Tom Collins", 73 | "Vieux Carré", 74 | "Whiskey Smash", 75 | "Whiskey Sour", 76 | ] 77 | 78 | 79 | def main(argv=sys.argv[1:]): 80 | arg_parser = ArgumentParser(description=__doc__) 81 | arg_parser.add_argument( 82 | "-C", "--clear-collection", action="store_true", default=False 83 | ) 84 | arg_parser.add_argument("-d", "--dummy-data", action="store_true") 85 | 86 | args = arg_parser.parse_args(argv) 87 | asyncio.run( 88 | amain(clear_collection=args.clear_collection, create_dummy_data=args.dummy_data) 89 | ) 90 | 91 | 92 | async def amain(clear_collection=False, create_dummy_data=True): 93 | client: AsyncIOMotorClient = AsyncIOMotorClient( 94 | Settings().mongodb_url, 95 | connectTimeoutMS=1000, 96 | socketTimeoutMS=1000, 97 | serverSelectionTimeoutMS=1000, 98 | ) 99 | db = client.get_default_database() 100 | await init_beanie(db, document_models=[Cocktail]) 101 | 102 | if clear_collection: 103 | print("Delete existing cocktails.") 104 | await Cocktail.delete_all() 105 | 106 | # Create the autocomplete index if necessary: 107 | recipes = Cocktail.get_motor_collection() 108 | if not await recipes.list_search_indexes("autocomplete_name").to_list(length=1): 109 | print("Create autocomplete index on 'name' field ...") 110 | await db.create_collection(recipes.name) 111 | await recipes.create_search_index( 112 | { 113 | "definition": { 114 | "mappings": { 115 | "dynamic": False, 116 | "fields": {"name": {"type": "autocomplete"}}, 117 | } 118 | }, 119 | "name": "autocomplete_name", 120 | } 121 | ) 122 | else: 123 | print("Autocomplete index already exists on 'name' field.") 124 | 125 | if create_dummy_data: 126 | print("Create dummy cocktail data.") 127 | json = Path("sample_data/hunters_moon.json").read_text() 128 | 129 | progress = tqdm(COCKTAIL_NAMES, desc="Loading Cocktails") 130 | for name in progress: 131 | # Load the seed cocktail: 132 | template_cocktail = Cocktail.model_validate_json(json) 133 | # Rename it to the current cocktail name: 134 | template_cocktail.name = name 135 | # Now remove between 0-3 ingredients, so the cocktails aren't all identical: 136 | for _ in range(randint(0, 3)): 137 | del template_cocktail.ingredients[ 138 | randint(0, len(template_cocktail.ingredients) - 1) 139 | ] 140 | # Finally, save the cocktail: 141 | await template_cocktail.save() 142 | progress.write(name) 143 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021, MongoDB Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------