I'm using Scala, Mongo DB, and the mongo-scala driver simple example to insert data into Mongo.
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "2.9.0"
// step 1 : connect to mongo
val mongoClient: MongoClient = MongoClient("mongodb://localhost:27017")
// step 2 : connect to db
val database: MongoDatabase = mongoClient.getDatabase("mydb")
// step 3 : get the collection
val collection: MongoCollection[Document] = database.getCollection("test")
// step 4 : create document
val doc: Document = Document("_id" -> 0, "name" -> "MongoDB", "type" -> "database", "count" -> 1, "info" -> Document("x" -> 203, "y" -> 102))
//step 5 : insert in to db
collection.insertOne(doc).results();
Here in the last step the method results()
is not found, but they gave it in the documentation.