title: How to implement noSQL database abstraction?
body: <p>I use CouchDB, a document oriented database that store data as JSON documents. I use Javascript on the backend, so I can directly store JS object. Currently I have a direct mapping between the models I store in CouchDB and my domain layer. I think it's not a good thing, because I'm totally dependant on this database.</p>
  
  <h2>Example</h2>
  
  <p>I have 2 entities <strong>users</strong> and <strong>projects</strong>.
  One user can have multiple projects, these models are represented as separate documents in the database:  </p>
  
  <p><strong>user document</strong>  </p>
  
  <pre><code>{
    "_id": "1",
    "entity": "user"
  }
  </code></pre>
  
  <p><strong>projects documents</strong><br>
  The relation are referenced by a property <strong>user_id</strong>.</p>
  
  <pre><code>{
    "_id": "2",
    "entity": "project",
    "user_id": "1",
    "name": "project1"
  }
  
  // other project document
  {
    "_id": "3",
    "entity": "project",
    "user_id": "1",
    "name": "project2"
  }
  </code></pre>
  
  <p>My question is:<br>
  <strong>Should I keep this convenient mapping between layers or should I create an abstraction layer that transform the models from the database into domain object ?</strong></p>
  
  <p>Example of a more convenient user domain object:</p>
  
  <pre><code>// _id property is replaced by id
  // entity property is removed
  // projects relations stand in a projects array
  {
    id: "1",
    projects: [
     { id: "2", name: "project1"},
     { id: "2", name: "project1"}
    ]
  }
  </code></pre>
  
  <p>Note: I would like to read the book "Domain Driven Design" from Eric Evans. Maybe it could help me to see how to manage such models abstractions.</p>