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.
schema.ts

In index.ts, import Animal, connect to MongoDB, and add some data to the database.
index.ts

Run the file with bun run.
terminal

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