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.