As said, there is no way to modify an existing BSONObj. But there is a workaround to do this without re-creating it from scratch. Suppose you have BSONObj mybson. And you want to change the "somefield" field.
mybson = mybson.removeField("somefield"); mybson = BSONObjBuilder().appendElements(mybson).append("somefield", newvalue).obj();
source share