Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

autoValue documentation for docId is misleading. #402

Open OliverColeman opened 4 years ago

OliverColeman commented 4 years ago

Just spent some time figuring out why a findOne(this.docId) in an autoValue function was causing an error. The documentation for this.docId says docId: The _id property of the document being inserted or updated but it turns out it's not just the _id of the document, it's a filter query like { '$in': [ 'rg8gSYhGaNQaJ3X8p' ] }.

coagmano commented 4 years ago

I think the docs represent the original intention, but if an update uses a query in the selector, it will be used instead as a result of this code:

  } else if (type === "update" && selector) {
    docId = typeof selector === 'string' || selector instanceof Mongo.ObjectID ? selector : selector._id;
  }

source

Not sure what the "correct" behaviour here should look like

Want to make a PR to update the docs?

CaptainN commented 4 years ago

Is this the correct behavior? I would think the property should be made to always return a document id, as documented, and intuitively.