添加MongoDB驱动程序
概述
在本指南中,您将学习如何将MongoDB驱动程序添加到您的项目中。
所需时间5分钟
您需要什么
为您的编程语言配置的环境。
步骤
提示
使用上面的语言选择器在语言之间切换。
使用NuGet
添加MongoDB .NET/C#驱动程序。MongoDB.Driver 用于所有新项目。
.NET CLI
dotnet add package MongoDB.Driver --version 2.17.0 包管理器
PM > Install-Package MongoDB.Driver -Version 2.17.0 包引用
<PackageReference Include=MongoDB.Driver" Version="2.17.0" />
使用 go mod
添加 MongoDB Go 驱动程序。
mkdir guides cd guides go mod init guides go get go.mongodb.org/mongo-driver/mongo
以下方式之一将 MongoDB Java 驱动程序添加到您的项目中
如果您使用 Maven,将以下内容添加到您的
pom.xml
依赖项列表中<dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-sync</artifactId> <version>4.7.0</version> </dependency> </dependencies> 如果您使用 Gradle,将以下内容添加到您的
build.gradle
依赖项列表中dependencies { implementation 'org.mongodb:mongodb-driver-sync:4.7.0' }
配置好依赖项后,请确保它们对您的项目可用,这可能需要运行依赖项管理器并在您的 IDE 中刷新项目。
使用 npm
将 MongoDB Node.js 驱动程序添加到您的项目中。
npm install mongodb
使用 pip
python3 -m pip install 'pymongo[srv]'
摘要
如果您成功完成了本指南中的程序,您已将 MongoDB 驱动程序添加到您的项目中。
在下一指南中,您将学习如何从 MongoDB 中检索数据。
另请参阅
其他 CRUD 指南