         l.splice(i, 1)
         i -= 1
 
-  $push: (d, k, upd) -> # Adds an item to an array.
+  # Adds an item to an array.
+  $push: (d, k, upd) ->
     l = dotGet(d, k)
     # $each 	append multiple items for array updates.
     if upd.$each?

    return 0

u1 =
  # [fields]
  $inc: (d, k, upd) -> dotSet(d, k, upd + dotGet(d, k)) # Increments the value of the field by the specified amount.
  $rename: (d, k, upd) -> # Renames a field.
    dotSet(d, upd, dotGet(d, k))
    dotDel(d, k)
  $setOnInsert: (d, k, upd, insert) ->	# Sets the value of a field upon documentation creation during an upsert. Has no effect on update operations that modify existing documents.
    return unless insert
    dotSet(d, k, upd)
  $set: (d, k, upd) -> dotSet(d, k, upd) #Sets the value of a field in an existing document.
  $unset: (d, k, upd) -> dotDel(d, k) # Removes the specified field from an existing document.
  # [Array][operators]
  # TODO: $ 	Acts as a placeholder to update the first element that matches the query condition in an update.
  $addToSet: (d, k, upd) -> # Adds elements to an existing array only if they do not already exist in the set.
    l = dotGet(d, k)
    # $each 	append multiple items for array updates.
    if upd.$each?


s1 = {}
s2 =
  ## [comparison]
  # Matches values that are greater than the value specified in the query.
  $gt:  (v,q) -> v >  q
  # Matches values that are equal to or greater than the value specified in the
  #  query.
  $gte: (v,q) -> v >= q
  # Matches any of the values that exist in an array specified in the query.
  $in:  (v,q) -> v in q
  # Matches values that are less than the value specified in the query.
  $lt:  (v,q) -> v <  q
  # Matches values that are less than or equal to the value specified in the
  #  query.
  $lte: (v,q) -> v <= q
  # Matches all values that are not equal to the value specified in the query.
  $ne:  (v,q) -> v != q
  # Matches values that do not exist in an array specified to the query.
  $nin: (v,q) -> v not in q
  # Matches arrays that contain all elements specified in the query.
  $all: (v,q) ->
    for x in v
      return false if x not in q
    true

  ## [element]
  # Matches documents that have the specified field.
  $exists: (v,q) -> v? == q
  # Performs a modulo operation on the value of a field and selects documents
  #  with a specified result.
  $mod: (v,q) -> (v % q[0]) == q[1]
  # TODO: $type: Selects documents if a field is of the specified type.

  ## [array]
  # Selects documents if the array field is a specified size.
  $size: (v,q) -> v.length == q
  # Selects documents if element in the array field matches all the specified
  #  $elemMatch condition.
  $elemMatch: (v,q) ->
    for x in v
      return true if s1.$m(x,q)
    false

  # Match
  $m: (v,q) ->
    for op, qv of q
      return false unless @[op](v,qv)
    return true

  ## [javascript]
  # TODO: $where: # Matches documents that satisfy a JavaScript expression.
  # TODO: $regex: # Selects documents where values match a specified regular expression.

  ## [geospatial]
  # TODO: $geoWithin: # Selects geometries within a bounding GeoJSON geometry.
  # TODO: $geoIntersects: # Selects geometries that intersect with a GeoJSON geometry.
  # TODO: $near: # Returns geospatial objects in proximity to a point.
  # TODO: $nearSphere: # Returns geospatial objects in proximity to a point on a sphere.

s1[k] = v for k,v of {
  ## [logical]
  # Joins query clauses with a logical OR returns all documents that match the
  #  conditions of either clause.
  $or:  (v,q) ->
    for xq in q
      return true if @$m(v,xq)
    false
  # Joins query clauses with a logical AND returns all documents that match the
  #  conditions of both clauses.
  $and: (v,q) ->
    for xq in q
      return false unless @$m(v,xq)
    true
  # Inverts the effect of a query expression and returns documents that do not
  #  match the query expression.
  $not: (v,q) ->
    return not @$m(v,q)
  # Joins query clauses with a logical NOR returns all documents that fail to
  #  match both clauses.
  $nor: (v,q) ->
    for xq in q
      return false if @$m(v,xq)
    true
