db.collection.update & WriteResult

73 views
Skip to first unread message

Vitaliy Morarian

unread,
Jan 10, 2017, 9:30:29 PM1/10/17
to ReactiveMongo - http://reactivemongo.org
Hi,

Documentation of update operation returns WriteResult 
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

 In case of error it also returns writeConcernError or writeError  

doesn't parse nUpserted (it reads `upserted`) or nMatched.

With 0.11 even a bit worse situation. It expects ok in response
And as result any update is treated as failed.

Am I right about these issues, or did I miss something?

Cédric Chantepie

unread,
Jan 12, 2017, 3:39:44 AM1/12/17
to ReactiveMongo - http://reactivemongo.org
Hi,

You are looking at the MongoShell update operation, not at the underlying command, which output the fields ok, n, nModified, upserted, writeErrors and writeConcernErrors, which are parsed by ReactiveMongo.

Vitaliy Morarian

unread,
Jan 12, 2017, 7:09:53 AM1/12/17
to ReactiveMongo - http://reactivemongo.org
Hi,

Great. At least it clears something. However, as I mentioned above - update with upsert doesn't work for me in 0.11.x (I see upserted or updated record in mongo, but driver returns error).
I debugged response:

{
  n: BSONInteger(1),
  nModified: BSONInteger(0),
  upserted: [
    0: {
      index: BSONInteger(0),
      _id: BSONObjectID("58776ebd4000004300bd3b07")
    }
  ],
  ok: BSONDouble(1.0)
}


ok is Double

But parsing is defined as
ok = doc.getAs[Int]("ok").exists(_ != 0),

And in master it's

ok = doc.getAs[BSONBooleanLike]("ok").fold(true)(_.toBoolean),

Is it a real cause why update doesn't work in 0.11.x?

Cédric Chantepie

unread,
Jan 12, 2017, 11:24:39 AM1/12/17
to ReactiveMongo - http://reactivemongo.org
If ok is a double, then you are using MongoDB > 3.2, problably 3.4.

Previous release 0.11 was not compatible with such MongoDB version.
Reply all
Reply to author
Forward
0 new messages