meteor-collection-hooks icon indicating copy to clipboard operation
meteor-collection-hooks copied to clipboard

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

Open jowilhnson opened this issue 9 years ago • 3 comments

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.

jowilhnson avatar Jan 19 '16 21:01 jowilhnson

+1

goooseman avatar Mar 08 '16 08:03 goooseman

Definitely a collection-hooks bug, thanks for the report

matb33 avatar Mar 28 '16 13:03 matb33

Is this still an issue?

StorytellerCZ avatar Sep 03 '22 11:09 StorytellerCZ