Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Does MyCollection.direct.update call MyCollection.update? #73

Closed
colllin opened this issue Nov 17, 2014 · 6 comments
Closed

[server] Does MyCollection.direct.update call MyCollection.update? #73

colllin opened this issue Nov 17, 2014 · 6 comments

Comments

@colllin
Copy link

colllin commented Nov 17, 2014

Or does it skip straight to the Mongo driver's update function?

When I try to update a document by _id, using:

Things.direct.update('254at4wta43t34', modifier, options);

I get the server-side error:

Exception while invoking method '/things/update' Error: selector must be a valid JavaScript object

which to me looks like a Mongo driver error. I expected it to call the Meteor Collection.update function directly, which would allow me to pass the ID instead of a selector object.

@matb33
Copy link
Collaborator

matb33 commented Nov 17, 2014

Ah interesting point, you're right, and it's because of: https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js#L50

I suspect to make this work properly would involve making sure that _super at https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js#L95 is always referencing the original mutator method and not _collection's

@colllin
Copy link
Author

colllin commented Nov 17, 2014

That looks like it! I meant to say Things.direct.update in my original example. I've updated it now, but it seems like you knew what I meant.

Looks like you went out of your way to make the server extend the underlying _collection though. Do you remember why?

@matb33
Copy link
Collaborator

matb33 commented Nov 17, 2014

Nope... don't remember, but it was for a good reason. I looked briefly and couldn't recall...

@colllin
Copy link
Author

colllin commented Nov 25, 2014

Dug a little more, and it looks like _collection is from your original attempt. Then later you moved to the Meteor.isClient ? self : self._collection logic.

Commit where you changed to that logic:
f3b9deb#diff-25a92cefdc8e3dd82dc7e3b4a90472bbL46

Original commit with the _collection logic:
8e5a8f1#diff-25a92cefdc8e3dd82dc7e3b4a90472bbR49

Oh well, at least you can get around it by passing {_id: <id>}

@matb33
Copy link
Collaborator

matb33 commented Dec 14, 2014

I believe that logic is important for firing server-defined hooks after allow/deny has been processed.

@colllin
Copy link
Author

colllin commented Jan 19, 2015

Great improvement. Thanks for this!

aramk added a commit to aramk/meteor-collection-hooks that referenced this issue Mar 13, 2015
…exceptions

* commit '7a96ab397710ad69592033f222b8481cd2dd3db9':
  update History and bump version to 0.7.11
  leverage the original constructor to accomplish direct operations, fixes Meteor-Community-Packages#89 and most likely Meteor-Community-Packages#90
  wip
  slight change to test logic for direct update and remove by string id to be certain we aren't reusing the collection from the test above it
  update api.versionsFrom to 1.0.3 and add tests to verify that direct update and remove work using the string _id
  update version and history
  attempt to prevent cfs tests from running on travis
  add collectionfs tests
  update history for 0.7.8
  change approach for direct to allow the advices to choose how to suppress the hooks, which allows us to have consistent return values -- fixes Meteor-Community-Packages#73 and Meteor-Community-Packages#86
  - re-add api.versionsFrom, it is needed... oops
  - remove unused bind polyfill - merge issue67 branch, which tests the collection hooks firing properly in a tight loop - remove api.versionsFrom(0.9.1), this is not necessary
  change _wrapAsync to wrapAsync
  add test for hooks in tight loop

Conflicts:
	insert.js
	remove.js
	update.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants