Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

The `_id` of documents in the `after.insert` hooks is not an object id #207

Closed mjyc closed 7 years ago

mjyc commented 7 years ago

The _id of documents in the after.insert hooks are no longer strings, but objects.

For example, using the following code

Collection.after.insert(
  function(userId, obj) {
    console.log(obj._id);
  }
)

We get the following outputs:

I20161214-00:51:38.409(-8)? local addition of  { result: 
I20161214-00:51:38.409(-8)?    { ok: 1,
I20161214-00:51:38.410(-8)?      n: 1,
I20161214-00:51:38.411(-8)?      opTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1481705498 } },
I20161214-00:51:38.411(-8)?   ops: 
I20161214-00:51:38.411(-8)?    [ { name: 'Room 123',
I20161214-00:51:38.411(-8)?        phone: '',
I20161214-00:51:38.411(-8)?        floorId: 'savidev/1',
I20161214-00:51:38.412(-8)?        pose: [Object],
I20161214-00:51:38.412(-8)?        goalarea: '',
I20161214-00:51:38.412(-8)?        doorOpensOut: false,
I20161214-00:51:38.412(-8)?        hidden: false,
I20161214-00:51:38.412(-8)?        _id: 'RmkvkGRjZ8DoLMqPy' } ],
I20161214-00:51:38.412(-8)?   insertedCount: 1,
I20161214-00:51:38.412(-8)?   insertedIds: [ 'RmkvkGRjZ8DoLMqPy' ] }

However, we expect obj._id to be the _id of the inserted document ("RmkvkGRjZ8DoLMqPy" in the above).

Tested in Meteor 1.4.2.3.

namirsab commented 7 years ago

Could you show me your package versions?

mjyc commented 7 years ago

It was matb33:collection-hooks@0.8.1

namirsab commented 7 years ago

Have you tried updating?. This bug was solved afaik

mjyc commented 7 years ago

Updated to 0.8.4 and I did not have the above problem anymore. Thank you.

namirsab commented 7 years ago

:)