org.mongodb.scala.FindObservable.execute() method missing base on example code

I am using Scala 2.12 with the following Maven coordinates:

  • org.mongodb.scala:mongo-scala-driver_2.12:4.6.0
  • org.mongodb.scala:mongo-scala-bson_2.12:4.6.0
  • org.mongodb:bson:4.6.0

I am following the MongoDB Scala Driver quick tour guide here:

I am successfully in making client connectivity to the Mongo server and select the collection without any issue.
I am having trouble querying the collection and the goal of obtain the resulting document collections in the form of Seq[JSON].

I am referencing and using the example Mongo (scala) code from here:

Here is my example code:

val exStartDt = LocalDate.of(2022,4,26) // exStartDt: java.time.LocalDate = 2022-04-26
val exEndDt = LocalDate.of(2022,4,27) // exEndDt: java.time.LocalDate = 2022-04-27
val exStartDateMilli = java.util.Date.from(exStartDt.atStartOfDay().atZone(ZoneId.of("UTC")).toInstant()).getTime() // exStartDateMilli: Long = 1650931200000
val exEndDateMilli = java.util.Date.from(exEndDt.atStartOfDay().atZone(ZoneId.of("UTC")).toInstant()).getTime() // exEndDateMilli: Long = 1651017600000
val exBdtStart = BsonDateTime(exStartDateMilli) // exBdtStart: org.mongodb.scala.bson.BsonDateTime = BsonDateTime{value=1650931200000}
val exBdtEnd = BsonDateTime(exEndDateMilli) // exBdtEnd: org.mongodb.scala.bson.BsonDateTime = BsonDateTime{value=1651017600000}
val mQuery = BsonDocument("createdDateTime" -> BsonDocument("$gte" -> exBdtStart, "$lt" -> exBdtEnd),
                          "_id" -> BsonDocument("$eq" -> "ABC1234567890"))
// mQuery: org.mongodb.scala.bson.BsonDocument = {"createdDateTime": {"$gte": {"$date": "2022-04-26T00:00:00Z"}, "$lt": {"$date": "2022-04-27T00:00:00Z"}}, "_id": {"$eq": "ABC1234567890"}}
val collection: MongoCollection[Document] = db.getCollection(myCollection)
// collection: org.mongodb.scala.MongoCollection[org.mongodb.scala.bson.Document] = MongoCollection(com.mongodb.reactivestreams.client.internal.MongoCollectionImpl@123456789)
var findObservable = collection.find(mQuery)
// mResult: org.mongodb.scala.FindObservable[org.mongodb.scala.bson.Document] = FindObservable(com.mongodb.reactivestreams.client.internal.FindPublisherImpl@123456789)
// error: value execute is not a member of org.mongodb.scala.FindObservable[org.mongodb.scala.bson.Document]
// println(findObservable.execute().size)
//                        ^

It is complaining that execute() is not a member of org.mongodb.scala.FindObservable[org.mongodb.scala.bson.Document].

None of the Scala Mongo client query code (that I can find) is current consistent and working for this basic query example.

I am current stuck and I could not find working examples that is current as of April 2022.
I appreciate any pointers or better references that can help me to accomplish my objectives.


I found the latest version of the ScalaDoc for org.mongodb.scala.FindObservable

and it does not have any function signature for execute().

How do I achieve the first basic objective of taking a resulting documents (based on the query I provided) into a list of JSON that I can work with in Scala?

My client connection to the MongoDB is good based on the client.getClusterDescription.

res0: com.mongodb.connection.ClusterDescription = ClusterDescription{type=SHARDED, connectionMode=SINGLE, serverDescriptions=[ServerDescription{, type=SHARD_ROUTER, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=161857314}]}

If there are other triaging or diagnostic methods I can run to illuminate this current issues, please free to chime in. Thanks!

I found another example reference code from here:


collection.find(gt("i", 50)).printResults()

I tried to use the same scala example for my example program

collection.find(equal("_id", "ABC1234567890")).printResults()

and still got error:

error: value printResults is not a member of org.mongodb.scala.FindObservable[org.mongodb.scala.bson.Document]
collection.find(equal("_id", "ABC1234567890")).printResults()

Is there an actual Scala Mongo example that works out there with the current code base that is available in April 2022 that can achieve my simple objective?