concept document in category meteor

This is an excerpt from Manning's book Meteor in Action.
All data is typically stored inside a MongoDB, a document-oriented NoSQL database. There are plans for Meteor to support other (SQL-based) database systems, but currently the only suggested database is Mongo. It provides a JavaScript API that gives access to all stored content in the form of documents or objects. The same language used inside the browser can be used to access data, which Meteor takes advantage of to implement true full-stack development.
Once the collection is set up, selecting a house performs a lookup in the server database and inserts the document for the currently selected ID into the LocalHouse collection. That means we need to revisit the events for the selectHouse template.
So far the only thing the change event on the drop-down list does is set the value for Session, so let’s enhance the existing code. Listing 5.2 shows the changes you need to make. When assigning a value to newId things get a little more complex, so we’ll look at the code from the inside out. The findOne() operation on the HousesCollection will return a document based on the currently selected ID. If the empty drop-down option was selected, it can’t find a document. In that case, you’ll use the newHouse object instead. Either way, after changing the drop-down option you’ll have a document.
Because you deal with either an existing doc (which would require using update()) or a new document (which must use insert()), you can use the flexible upsert() method. If it finds an existing document based on its _id, it’ll perform an update; otherwise, it’ll insert a whole new document. When performing an update upsert() returns how many documents were affected; when inserting a new document it returns an object with two attributes: numberAffected and insertedId. Either way the returned value for insertedId is assigned to newId, which will become the new value for selectedHouseId. If upsert() doesn’t need to insert any new documents into the local collection, it means a document with the selected ID is already present and should be used as newId.
Laziness is a virtue for programmers, so let’s use only a single event for changes to either the color or instructions attribute of a plant. That way, you’ll get updates to all available plant attributes for free, should you ever decide to add, say, a location field. That means you have to determine not only the value of what to insert into the document but also the field name or where to insert it. To uniquely identify a property, you need three pieces of information:
Listing 7.7. Observing changes in a collection
WorkoutsCollection .find( query ) .observeChanges({ added: function(id, fields){ // do something if a document was added matching the query }, changed: function(id, fields){ // do something if a document of the query changed }, removed: function(id){ // do something if a document of the query was removed } });