文档菜单
文档首页
/
从指南开始

添加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 指南

  • 在MongoDB中读取数据

  • 使用查询从MongoDB中读取数据

  • 使用运算符和复合查询读取数据

  • 将数据插入MongoDB

  • 更新MongoDB中的数据

  • 从MongoDB中删除数据

下一步是什么
在MongoDB中读取数据
10分钟

没有查询,检索 MongoDB 中的文档。

入门指南
章节2
CRUD
  • 添加MongoDB驱动程序
  • 在MongoDB中读取数据
  • 使用查询从MongoDB中读取数据
  • 使用运算符和复合查询读取数据
  • 将数据插入MongoDB
  • 更新MongoDB中的数据
  • 从MongoDB中删除数据