为什么我连接上了mongodb 操作数据库的时候没反应求解


        org.scala-lang
        scala-library
        2.11.8
    

    
        org.mongodb.scala
        mongo-scala-driver_2.11
        2.7.0
    

import org.mongodb.scala.MongoClient
import org.mongodb.scala.bson.collection.immutable.Document

/*

  • @author: ljx

  • @date:

  • @description: scala连接mongodb,有权限认证
    */

     object pojo4 {
       def main(args: Array[String]): Unit = {
       //连接mongodb  OK
    
       val connectionString: String = "mongodb://interface_manager:2wsxCDE#@host:50000/?authSource=admin"
       val mongoClient: MongoClient = MongoClient(connectionString)
       val mongoDB = mongoClient.getDatabase("xzq_test")
      val coll = mongoDB.getCollection("collection")
    //连接成功下面操作全部没反应,程序已经走完
    println(coll.count())
    

//下面没执行

	  coll.find().foreach(x =>print(x))
	 val doc: Document = Document("_id" -> 0, "name" -> "MongoDB", "type" -> "database",
    "count" -> 1, "info" -> Document("x" -> 203, "y" -> 102))
	  coll.insertOne(doc)
	   coll.find().foreach(x =>print(x))


	  }
	}

你可能感兴趣的:(scala)