# Using design documents in pouchDB with crypto-pouch

**URL:** <https://forum.ionicframework.com/t/using-design-documents-in-pouchdb-with-crypto-pouch/42445>\
**Category:** ionic-v1\
**Created:** [January 30, 2016, 1:50pm UTC](https://forum.ionicframework.com/t/using-design-documents-in-pouchdb-with-crypto-pouch/42445 "2016-01-30T13:50:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![max\_maeuschen](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@max\_maeuschen](https://forum.ionicframework.com/u/max_maeuschen)\
**Post date:** [January 30, 2016, 1:50pm UTC](https://forum.ionicframework.com/t/using-design-documents-in-pouchdb-with-crypto-pouch/42445/1 "2016-01-30T13:50:06Z")

</div>

After testing pouchDB for my Ionic project, I tried to encrypt my data with crypto-pouch. But I have a problem with using design documents. I used the following code:

One of my design documents:

> ```
> var allTypeOne = {
> _id: '_design/all_TypeOne',
> views: {
> 'alle_TypeOne': {
> map: function (doc) {
> if (doc.type === 'type_one') {
> emit(doc._id);
> }
> }.toString()
> }
> }
> };
> 
> ```

For init my database:

> ```
> function initDB() {
> _db = new PouchDB('myDatabase', {adapter: 'websql'});
> if (!_db.adapter) {
> _db = new PouchDB('myDatabase');
> }
> return _db.crypto(password)
> .then(function(){
> return _db;
> });
> 
> ```

> ```
> // add a design document
> _db.put(allTypeOne).then(function (info) {
> 
> ```

> ```
> }).catch(function (err) {
> 
> ```

> ```
> }
> }
> 
> ```

To get all documents of type\_one:

> ```
> function getAllData {
> if (!_data) {
> return $q.when(_db.query('all_TypeOne', { include_docs: true}))
> .then(function(docs) {
> _data = docs.rows.map(function(row) {
> return row.doc;
> });
> _db.changes({ live: true, since: 'now', include_docs: true})
> .on('change', onDatabaseChange);
> return _data;
> });
> } else {
> return $q.when(_data);
> }
> }
> 
> ```

This code works without using crypto-pouch well, but if I insert the \_db.crypto(…) no data is shown in my list. Can anyone help me? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jeffleus](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jeffleus](https://forum.ionicframework.com/u/jeffleus)\
**Post date:** [June 14, 2016, 8:58pm UTC](https://forum.ionicframework.com/t/using-design-documents-in-pouchdb-with-crypto-pouch/42445/2 "2016-06-14T20:58:03Z")

</div>

I have been recently working w/ this pouch plugin as well. I was having similar problems until I destroyed the db and started over. In my model, I have a set of (3) design docs for (3) data types that return data. And, I have a CouchDB server that I run replication/sync against. Once I destroyed the local db and started over, the issues went away. Upon recreating and syncing the local db w/ crypto “ON”, the design docs (and all data docs) were appropriately encrypted and the views from the design docs began working.

-Jeff
