简体   繁体   中英

error: unresolved reference: mongodb in Kotlin

I am new to Kotlin. I want to perform basic CRUD operations with Mongo DB and I get the following error:

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).

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

What am I missing?

EDIT This is the project hierarchy. I work with 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/


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)

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

If you cannot see the MongoDB library from there, there is a possibility that IDE has some problems. So I would recommend reset caches( File -> Invalidate Caches / Restart ), clean build, and rebuild the project.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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