title: Mongoose product category design?
body: <p>I would like to create an eCommerce type of database where I have products and categories for the products using Mongodb and Mongoose. I am thinking of having two collections, one for products and one for categories. After digging online, I think the category should be as such:</p>
  
  <pre><code>var categorySchema = {
    _id: { type: String },
    parent: {
      type: String,
      ref: 'Category'
    },
    ancestors: [{
      type: String,
      ref: 'Category'
    }]
  };
  </code></pre>
  
  <p>I would like to be able to find all the products by category. For example "find all phones." However, the categories may be renamed, updated, etc. What is the best way to implement the product collection? In SQL, a product would contain a foreign key to a category.</p>
  
  <p>A code sample of inserting and finding a document would be much appreciated!</p>