Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created July 17, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/e798b62a8b7f41136d0a to your computer and use it in GitHub Desktop.
Save nolanlawson/e798b62a8b7f41136d0a to your computer and use it in GitHub Desktop.
Test PouchDB Map/Reduce error 1
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/pouchdb/2.2.3/pouchdb.min.js"></script>
<script src="index.js"></script>
</body>
</html>
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