Created
July 17, 2014 17:36
-
-
Save nolanlawson/e798b62a8b7f41136d0a to your computer and use it in GitHub Desktop.
Test PouchDB Map/Reduce error 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/pouchdb/2.2.3/pouchdb.min.js"></script> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = PouchDB('localDB'); | |
var item1 = {_id: 'item_1', key: 'value1'}; | |
var item2 = {_id: 'item_2', key: 'value2'}; | |
var mapFn = function(doc){ | |
emit(doc._id); | |
}; | |
db.put(item1).then(function(){ | |
console.log('put item1', 'ok'); | |
return db.put(item2); | |
}).then(function(res){ | |
console.log('put item2', 'ok'); | |
return db.query({map: mapFn}, {key: 'value1'}); | |
}).then(function(){ | |
console.log('query key: value1', 'ok'); | |
return db.query({map: mapFn}, {key: 'value2'}); | |
}).then(function(){ | |
console.log('query key: value2', 'ok'); | |
db.destroy(); | |
}).catch(function(err){ | |
console.log('error', err); | |
db.destroy(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment