简体   繁体   English

错误:未解决的参考:Kotlin 中的 mongodb

[英]error: unresolved reference: mongodb in Kotlin

I am new to Kotlin.我是 Kotlin 的新手。 I want to perform basic CRUD operations with Mongo DB and I get the following error:我想使用 Mongo DB 执行基本的 CRUD 操作,但出现以下错误:

error: unresolved reference: mongodb

for this line of code:对于这行代码:

import com.mongodb.BasicDBObject

I have added the following dependency in the build of the module in Android Studio (Intellij IDE).我在 Android Studio (Intellij IDE) 中的模块构建中添加了以下依赖项。

implementation 'org.mongodb:mongodb-driver-sync:3.11.0'

What am I missing?我错过了什么?

EDIT This is the project hierarchy.编辑这是项目层次结构。 I work with DBOps.kts我与 DBOps.kts 合作

项目层次结构

I think you are using legacy code.我认为您正在使用遗留代码。

Here is the correct one for that.这是正确的。

dependencies {
      compile 'org.mongodb:mongo-java-driver:2.13.3'
}

Reference: https://mongodb.github.io/mongo-java-driver/2.13/getting-started/installation-guide/参考: https://mongodb.github.io/mongo-java-driver/2.13/getting-started/installation-guide/


EDIT编辑

I have tried myself, and it works, so I guess there is another issue.我自己试过了,它有效,所以我想还有另一个问题。 After importing library via Gradle, you could check it is imported correctly from Project -> External Libraries (Check below image)通过 Gradle 导入库后,您可以从Project -> External Libraries检查它是否正确导入(检查下图)

在此处输入图像描述 在此处输入图像描述

If you cannot see the MongoDB library from there, there is a possibility that IDE has some problems.如果从那里看不到 MongoDB 库,则 IDE 可能存在一些问题。 So I would recommend reset caches( File -> Invalidate Caches / Restart ), clean build, and rebuild the project.所以我建议重置缓存( File -> Invalidate Caches / Restart ),清理构建并重建项目。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM