mcfinley
mcfinley

Reputation: 11

Meteorjs server side call

I have a task like this:

Create a meterojs app. This app should provide an ability for users to add messages (without explicit server side call) and to remove it (only using server side call).

I'm a newbie with meteorjs and i dont understand how can an entity be put to the collection without a server side call.

Is there any way to do this?

Upvotes: 1

Views: 75

Answers (1)

zim
zim

Reputation: 2386

it's an odd task, but it works like this: Meteor maintains a client-side "mini mongo" that

  • houses the data published from the server
  • allows mongo-like queries on that data
  • allows CRUD operations that sync with mongo behind the scenes

let's say you define a collection, messages, in a file that is served to both the client and the server:

Messages = new Mongo.Collection('messages');

Meteor will:

  • if not already created, create a mongo collection called 'messages' in the database
  • create a minimongo collection called 'messages' on the client
  • define a symbol, 'Messages', on both the client and the server that has the typical mongo functions (e.g. find(), findOne(), insert(), etc)

by default, any operations you make client-side will be reflected server-side, behind the scenes. thus, your user can add a message without an explicit server-side call (i.e. its implicit).

that data will actually exist in the real mongo database. so now you have the ability, from the server, to delete it. if there is an active publish on that collection, the client will be updated with that deletion.

Upvotes: 1

Related Questions