Skip to content

Instantly share code, notes, and snippets.

@xosofox
Last active December 12, 2015 10:09
Show Gist options
  • Save xosofox/4756807 to your computer and use it in GitHub Desktop.
Save xosofox/4756807 to your computer and use it in GitHub Desktop.
if (Meteor.isServer) {
// update the appropriate rsvp entry with $
Parties.update(
{_id: partyId, "rsvps.user": this.userId},
{$set: {"rsvps.$.rsvp": rsvp}});
} else {
// minimongo doesn't yet support $ in modifier. as a temporary
// workaround, make a modifier that uses an index. this is
// safe on the client since there's only one thread.
var modifier = {$set: {}};
modifier.$set["rsvps." + rsvpIndex + ".rsvp"] = rsvp;
Parties.update(partyId, modifier);
}
}
@xosofox
Copy link
Author

xosofox commented Feb 11, 2013

I would need some help on the "Black Mongo Magic" that is going on here:

  1. What is the $ in line 5? An index? But how is it defined? Where can I find more details on that in the mongo docs?
  2. How is the workaround on the client side working? A $set on a $set? 😕

@jmikola
Copy link

jmikola commented Feb 11, 2013

  1. What is the $ in line 5? An index? But how is it defined? Where can I find more details on that in the mongo docs?

http://docs.mongodb.org/manual/reference/operator/positional/

  1. How is the workaround on the client side working? A $set on a $set?

Looks like a workaround for the minimongo library's overly strict validation of find() and update() arguments. Perhaps it complains about using $ as a component in a field path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment