Skip to main content
MongoDB 和 Mongoose 无需额外配置即可与 Bun 一起使用。本指南假设你已经安装了 MongoDB,并将其作为后台进程或服务运行在开发机器上。详情请参阅 MongoDB 安装指南
MongoDB 运行后,创建一个目录并用 bun init 初始化。
terminal

然后添加 Mongoose 作为依赖。
terminal

schema.ts 中声明并导出一个 Animal 模型。
schema.ts

index.ts 中导入 Animal,连接到 MongoDB,并向数据库中添加一些数据。
index.ts

使用 bun run 运行该文件。
terminal

在构建应用程序时,请参阅官方的 MongoDBMongoose 文档。