title: Mongoose: ObjectId Comparisons fail inconsistently
body: <p>I have a straightforward tool for building collections of documents and then automatically formatting them for EPUB or LaTeX rendering, written on top of ExpressJS.  I'm using Coffeescript, if that matters (I doubt it).</p>
  
  <p>Using Mongoose, I have the following:</p>
  
  <pre><code>DocumentSchema = new Schema
      title:     String
  
  Offrefs = new Schema
      ref:       { type: ObjectId }
      isa:       String
  
  BinderSchema = new Schema
      title:     String
      contains:  [Offrefs]
  </code></pre>
  
  <p>Offrefs doesn't specify what it refers to because because I want to be able to contain some binders in other binders, to create logical collections: "These are for the printer," "These are for epub," "These are web only," etc.  (I've stripped out all the miscellaneous stuff out.)</p>
  
  <p>Unfortunately, I have run into queries where, for retrieved objects</p>
  
  <pre><code>(story._id == offref.ref) -&gt; True 
  </code></pre>
  
  <p>And the two do indeed look the same.  But:</p>
  
  <pre><code>(binder._id == offref.ref) -&gt; False
  (String(binder._id) == String(offref.ref)) -&gt; True
  </code></pre>
  
  <p>And a visual comparison of the two references in the last two, they <em>are</em> the same ID number, but the <code>ObjectId</code> objects don't compare correctly.</p>
  
  <p>I don't want to have to do string conversions constantly, which is a strong possiblity when I'm converting these complex objects into trees of data.  Tree relationships are a bear in any DB; they shouldn't be difficult in MongoDB.</p>
  
  <p>How do you do ObjectId comparisons in MongoDB?</p>