     # Setup observers only for local collections or server collection. Collections based
     # on a connection to some other primary collections should not have observers because
     # they should be setup at the location of primary collections, not here.
-    for document in @list when document.Meta.collection._connection in [null, Meteor.server]
+    for document in @list when (Meteor.isClient and document.Meta.collection._connection is null) or (Meteor.isServer and document.Meta.collection._connection in [null, Meteor.server])
       if updateAll
         # For fields we pass updateAll on.
         setupTargetObservers document.Meta.fields


    unless updateAll
      for index in indexes
        @Meta.collection._ensureIndex index if @Meta.collection._connection is Meteor.server

    initializing = true

    observers =
      added: globals.Document._observerCallback (id, fields) =>
        @_sourceUpdated id, fields if updateAll or not initializing

    unless updateAll
      observers.changed = globals.Document._observerCallback (id, fields) =>
        @_sourceUpdated id, fields

    handle = @Meta.collection.find({}, fields: sourceFields).observeChanges observers

  projection

# TODO: Should we add retry?
globals.Document._observerCallback = (collection, f) ->
  # We observe only collections without connection or server collections.
  assert (Meteor.isClient and collection._connection is null) or (Meteor.isServer and collection._connection in [null, Meteor.server]), collection._connection

  return (obj, args...) ->
    try
      id = if _.isObject obj then obj._id else obj
      # We call f only if the first character of id is in PREFIX. By that we allow each instance to
      # operate only on a subset of documents, allowing simple coordination while scaling.
      # We call f always for collections without connection.
      f obj, args... if collection._connection is null or id[0] in PREFIX
    catch e
      Log.error "PeerDB exception: #{ e }: #{ util.inspect args, depth: 10 }"
      Log.error e.stack
