Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks

Home Page:https://atmospherejs.com/matb33/collection-hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meteor 2.6: after.insert callback does not contain correct document _id

KoenLav opened this issue · comments

Both this._id and doc._id do not contain the correct ID of the recently inserted document in the after.insert callback.

For me it will always show 1, instead of the random string of _id which is in the database.

Related: meteor/meteor#11867

The issue is inside this ternary:

const collection = Meteor.isClient || method === 'upsert' ? self : self._collection

This package is using _collection which is a private interface in the server. The public collection interface already handles this for all updates in the underlying mongo driver.

https://github.com/meteor/meteor/blob/4bc0b7f8cd12a15e03b69d6a72879c251582489f/packages/mongo/collection.js#L576

If the choice is to keep using it your PR might solve it, but it's not future proof regarding nodejs drivers update ;)

Meteor's mongo@1.14.4 package fixes the behavior on _collection, so this issue should be solved. lmk if that's not the case