I was wondering if it is possible that a server can subscribe to a collection from the clients so that only the server got everything and the users only have their local copy of the data.
I would like to create a meteor (mobile) app where people can create some content and store it in a collection (only local on the device) that noone can see except the "owner" itself locally and the server who owns everything. If a local collection is created the server subscribes to that collection so the server can collect all the data from every user and show it e.g. on a website. So I have 3 Components. The mobile app that generates the content (clients), the server that collects everything, and a website that only read the db with the complete content.
so,
is it possible that a server can subscribe to every collection from every user?
Yes, but the idea is: every subscribed user (client) is allowed to see his data. Have a look at the collection.allow(options) documentation. A client subscribes to a collection and the server decides what the client can see.
If you have some kind of authentication (or if you use the Accounts Meteor package) you can use Meteor.publish()on server side to only publish what belongs to the current user.
For example:
//Common Collection for both client and server (declared in lib/ for example):
//(will be a full DB on the server and a minimongo with published data only
//on the client)
Data = new Mongo.Collection('Data');
//Server: (publish to client only what belongs to the user)
Meteor.publish('userData', function(){
return Data.find({your_user_id_field:this.userId});
});
//Client: (the client only gets the data that belongs to him/her)
Meteor.subscribe('userData');
[... use the local collection as usual ...]
Related
Do we need to wait or flush user events or property before fetching remote config in Firebase in order to get the correct one?
Here's my setup:
I have two apps that shares the same Firebase app. The reason they share the same app is that I need to track conversion between the two apps, and can't find any better way!?
So I've created a User Propery, "Is_Lite_Version", and will create an AB for a remote config.
On launch, the app will both set the User Propery and fetch remote config.
My question is, could there be a problem here, due to latency? Where the remote config is fetch before the User Propery has been set, and then not getting the correct value?
Thanks in advance
I'm slightly confused about the availability of a collections, and exactly what happens when I use them in different places. I have a collection at /imports/api/clubs When I use it in my Meteor.methods it works fine. If I then import it into say a template file /imports/ui/pages/new_club.js and insert something into it, will it update the local cache only? Is the local collection reactive, i.e. will my helpers re-run?
A Meteor collection contains 0-N documents. A collection can be managed or unmanaged.
A managed collection:
is persisted via MongoDB on a server. It will survive either the client or the server stopping.
Exists only on the server unless it is published to the client via either the autopublish package or via one or more publications
the server automatically has read-write access to all documents in the collection
publications can be used to restrict the subset of the documents (both which documents and which keys) are available to any particular client.
changes to a collection on the server are automatically and asynchronously propagated to the affected client(s) via Meteor's DDP protocol which normally runs over WebSocket.
if changes are made to a collection from the client, the client's view is immediately updated (called an "optimistic update", part of Meteor's "latency compensation") and then the server attempts to make the same change. The server version ultimately "wins" in that changes from the server are asynchronously re-propagated back to the affected client(s).
An unmanaged collection:
exists only on the client
can be written to and read from only from the client
is not shared between clients
On the server side Meteor has access to the full MongoDB API. On the client side, Meteor has implemented "minimongo" which presents a restricted API. Minimongo is notably missing mongodb's aggregation framework as well as geo-queries.
Finally, to answer your specific question: yes, collections are reactive to changes made anywhere, either on the client you're on, by the server, or initiated on someone else's client
I need to sync the number of online users in each chat room to my elastic search repository (the one that searches for rooms).
Is there a way to attach a webhook server-side onto the connect and disconnect events that fire in firebase so that I can inc and decrement the user counts in my elastic search records?
I would probably use a node.js client for this. That way you can write your client against the same JavaScript SDK that you're already using.
In that client you would subscribe to the same events on the same paths as you would do in a regular front-end client. But instead of updating the UI, you'd just update a node in Firebase itself.
So a regular Firebase client would:
accept user input and send it to Firebase
listen for changes in Firebase an update the user's screen
This node.js client would instead:
listen for changes in Firebase and update the data in Firebase based on that
As Kato mentions: Flashlight is a perfect example of such an application, synchronizing data from Firebase to ElasticSearch and fielding ES queries by queueing them through Firebase.
I've posted this in Firebase's google group but haven't received an answer so I thought I would try here.
Let me outline my current scenario
I have a global messages bucket that stores messages by room. So path messages/room_1/ would store a prioritized list of messages for room 1.
I want to stream the latest messages for all rooms so that I can send push notifications to offline users. So essentially I want to listen to the /messages path from a ruby or python backed server and send notifications to offline users.
My problem is that when I initially start listening to the /messages path I get the entire set of data, which can be millions of messages. After the initial bulk load, I get new incoming messages in real time. Is there any way to skip that initial bulk load of data and just get new messages from the start of the streaming connection?
Fyi, I'm using examples from this page: https://www.firebase.com/blog/2014-03-24-streaming-for-firebase-rest-api.html
I'd like to better understand how the subscription model works - let's say I have some global subscriptions ie. they are loaded when the client starts, assuming it's the client's first connection to the Meteor server then all required data will be populated in minimongo and kept in sync with the server for the duration of the session.
But what happens when the client closes the app and reconnects at later stage:
Is the local store kept indefinitely on the client?
If above is true, then when the user re-connects would the data be synced to handle any differences between the local and server dbs?
Minimongo is an in-memory javascript datastore. Because it is not persisted to disk, none of the data will be available after the client browser/tab is closed. When a client reconnects, minimongo will be empty and all active subscription data will be synced as if for the first time.