Create A Dynamic Meteor Collection Using A Variable
I am trying to create a dynamic meteor collection using a variable so a new meteor collection will be created everytime an form is submitted and an event is executed. See code belo
Solution 1:
Don't do this. Asking how to create dynamic collections comes up periodically with new meteor developers, but it's never the right approach. @david-wheldon has a great description of why not to do this at the bottom of this page.
Just use one collection Messages
, containing documents something like this:
{ _id: xxxxxx,
sender: 'x533hf4j3i',
recipient: 'jf83jfu39d',
message: 'Hi there!',
...
timestamp, etc
...
}
Then it depends on your app if a user can view messages they did not send/receive, and if you need filtering on this you would do it server side in a publish function.
Either way, on the Client if you just want the messages between two users you would query like this:
chatMessages = Messages.find(
{$or: [{ sender: 'x533hf4j3i', recipient: 'jf83jfu39d'},
{ sender: 'jf83jfu39d', recipient: 'x533hf4j3i'}
]}).fetch()
Post a Comment for "Create A Dynamic Meteor Collection Using A Variable"