Meteor-Community-Packages / meteor-collection-hooks

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

findOne({},{fields:{_id:0}}) errors #174

Open jowilhnson opened 8 years ago

jowilhnson commented 8 years ago

After adding the collection-hooks package, I am now getting errors anywhere I have a call to find one that is set to only return specific fields and not include the _id field, such as:

var orderItems = Orders.findOne({_id:orderID},{fields:{_id:0,items:1}});

causes:

 Exception while invoking method 'ProcessItems' Error: can only transform documents with _id
    at [object Object].wrapped [as _transform] (packages/minimongo/packages/minimongo.js:1099:1)
    at [object Object]._.extend._nextObject (packages/mongo/mongo_driver.js:1003:1)
    at [object Object]._.extend.forEach (packages/mongo/mongo_driver.js:1020:1)
    at [object Object]._.extend.map (packages/mongo/mongo_driver.js:1030:1)
    at [object Object]._.extend.fetch (packages/mongo/mongo_driver.js:1054:1)
    at [object Object].Cursor.(anonymous function) [as fetch] (packages/mongo/mongo_driver.js:869:1)
    at [object Object].MongoConnection.findOne (packages/mongo/mongo_driver.js:776:1)
    at Object.collection.(anonymous function) [as findOne] (packages/matb33_collection-hooks/collection-hooks.js:104:1)
   at [object Object]._.extend.findOne (packages/mongo/collection.js:305:1)
   at packages/matb33_collection-hooks/collection-hooks.js:98:1    

Even though that particular collection doesn't have any hooks. Changing to

var orderItems = Orders.findOne({_id:orderID},{fields:{items:1}});

gets rid of the exception, so it's easy to work around, I just didn't find any mention or warning about this in the documentation anywhere. Not sure that it's a bug or just a necessity of how collection hooks works, though it seems if a collection doesn't have any hooks, the package shouldn't be stepping into the middle of the processing and requiring the _id field like this. Makes me a little concerned about how much extra overhead this package is adding to each and every collections call.

goooseman commented 8 years ago

+1

matb33 commented 8 years ago

Definitely a collection-hooks bug, thanks for the report

StorytellerCZ commented 2 years ago

Is this still an issue?