# Using pouchDB with crypto-pouch in ionic

**URL:** <https://forum.ionicframework.com/t/using-pouchdb-with-crypto-pouch-in-ionic/42444>\
**Category:** ionic-v1\
**Created:** [January 30, 2016, 1:23pm UTC](https://forum.ionicframework.com/t/using-pouchdb-with-crypto-pouch-in-ionic/42444 "2016-01-30T13:23:06Z")\
**Posts on this page:** 1\
**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:23pm UTC](https://forum.ionicframework.com/t/using-pouchdb-with-crypto-pouch-in-ionic/42444/1 "2016-01-30T13:23:06Z")

</div>

After testing pouchDB for my Ionic project, I tried to encrypt my data with crypto-pouch. I used the following code:

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;
> });
> }
> 
> ```

My function to map my documents:

> ```
> function mapAllTypeOne(doc) {
> if (doc.type === 'type_one') {
> emit(doc._id);
> }
> }
> 
> ```

To get all documents of type\_one:

> ```
> function getAllData {
> if (!_data) {
> return $q.when(_db.query(mapAllTypeOne, { 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);
> }
> }
> 
> ```

If I insert data of type\_one, I can see it in my database and it is encrypted in the database. But I couldn’t see it in my list. After a reload (in the browser) or after closing and restarting the app (in android or iOS) the new data can be seen.

Whitout crypto-pouch the code is working well. Can anyone help me? Thanks in advance!
