-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.0.0-beta2
-
Component/s: None
-
None
When inserting objects, BulkWrite::insert() only returns an ID if it needed to be generated. Otherwise, the userland library falls back to attempting to extra the ID from the inserted document, which may be an array or object.
Objects implementing the BSON Serializable interface may not have a public _id property, which may lead to either of two error messages:
- Undefined property: CLASSNAME::$_id
- Cannot access protected property ::$_id
While PHPC-382 will ultimately resolve this by changing BulkWrite::insert() to always return the inserted ID (not only when generated), a temporary workaround for Serializable instances requires that we invoke bsonSerialize() from userland and extract an "_id" key from the returned array or object.
- duplicates
-
PHPLIB-136 Refactor $insertedIds collection for insert operations
- Closed
- is related to
-
PHPC-382 Allow zval_to_bson() to return the ID irrespective of ID generation
- Closed
-
PHPC-471 BulkWrite::insert() should always return the document's ID
- Closed
- links to