Skip to main content
MongoDB and Mongoose work with Bun with no extra configuration. This guide assumes you’ve already installed MongoDB and are running it as a background process or service on your development machine. See the MongoDB installation guide for details.
Once MongoDB is running, create a directory and initialize it with bun init.
terminal

Then add Mongoose as a dependency.
terminal

In schema.ts, declare and export an Animal model.
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bschema.ts

In index.ts, import Animal, connect to MongoDB, and add some data to the database.
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bindex.ts

Run the file with bun run.
terminal

As you build your application, refer to the official MongoDB and Mongoose docs.