Where is my insert method?

30 views
Skip to first unread message

Andrew Zelinski

unread,
Jul 16, 2016, 9:20:41 PM7/16/16
to ReactiveMongo - http://reactivemongo.org
Hello, 

following the most basic examples, I cant even find how to insert a document. what am I missing?

val driver = new MongoDriver
val connection = driver.connection(List("localhost"))
val db = connection.database("test")
val collection = db.map(_ ("gr"))


and then 

val document = BSONDocument(
"firstName" -> "Stephane",
"lastName" -> "Godbillon",
"age" -> 29)

val future1: Future[WriteResult] = collection.insert(document)


and then 
[error] Sandbox/src/main/scala/ma.scala:28: object insert is not a member of package collection
[error]   val future1: Future[WriteResult] = collection.insert(document)
[error]                                                 ^
[error] one error found


What is going on?

BEBEBE

unread,
Jul 16, 2016, 9:22:04 PM7/16/16
to ReactiveMongo - http://reactivemongo.org
also, in IDE insert is highlighted red with "cannot resolve symbol" error, not sure why that didnt show here..

Cédric Chantepie

unread,
Jul 17, 2016, 7:44:06 PM7/17/16
to ReactiveMongo - http://reactivemongo.org
It seems there is a misunderstanding about the type of the 'collection' val (which is a Future), and that the IDE is not very helpful there.

I would suggest you try to declare this val with explicit type to have the compiler helping to see what it is.

BEBEBE

unread,
Jul 17, 2016, 9:51:02 PM7/17/16
to ReactiveMongo - http://reactivemongo.org
good call. we may want to consider a small clarification in the docs. the "getting started" examples are not completely accurate

Cédric Chantepie

unread,
Jul 18, 2016, 7:14:20 AM7/18/16
to ReactiveMongo - http://reactivemongo.org
If you have a look at the up-to-date documentation, you can see that collection is mentioned to be BSONCollection ( http://reactivemongo.org/releases/0.11/documentation/tutorial/write-documents.html ).

The documentation is also indicating how to get a this kind of collection reference from the database ( http://reactivemongo.org/releases/0.11/documentation/tutorial/database-and-collection.html ), which itself must be resolved from the connection pool ( http://reactivemongo.org/releases/0.11/documentation/tutorial/connect-database.html ).

It's recommanded to go step by step (note that all examples are compiled).

BEBEBE

unread,
Jul 21, 2016, 7:08:57 PM7/21/16
to ReactiveMongo - http://reactivemongo.org
but this documentation is all over the place. it says this:

Getting a database and a collection is pretty easy:

import scala.concurrent.ExecutionContext.Implicits.global

def connection5: reactivemongo.api.MongoConnection = ???

val db5 = connection5.database("somedatabase")
val collection5 = db5.map(_.collection("somecollection"))
and then the next page says this:

A collection can be resolved from the database, thanks to the collection.

import reactivemongo.api.collections.bson.BSONCollection

def db3: reactivemongo.api.DefaultDB = ???

val collection3 = db3.collection[BSONCollection]("acollection")

which does not work, at least the way its described.

For documentation improvements, this might be a case where one full example is better then the 6 pages of semi-connected thoughts
Reply all
Reply to author
Forward
0 new messages