Created
October 14, 2015 18:27
-
-
Save telekosmos/5e9b606e7aef6a2abe8d to your computer and use it in GitHub Desktop.
PouchDB querying nested objects
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 heroes = [ | |
{ | |
id: 5, | |
name: 'Batman', | |
realName: 'Bruce Wayne', | |
equipments: [ | |
{ | |
type: 'boomarang', | |
name: 'Batarang', | |
}, | |
{ | |
type: 'cloak', | |
name: 'Bat Cloak', | |
}, | |
{ | |
type: 'bolas', | |
name: 'Bat-Bolas', | |
} | |
] | |
}, | |
{ | |
id: 6, | |
name: 'Cat Woman', | |
realName: 'Selina Kyle', | |
equipments: [ | |
{ | |
type: 'car', | |
name: 'Cat-illac', | |
}, | |
{ | |
type: 'bolas', | |
name: 'Cat-Bolas', | |
} | |
] | |
} | |
]; |
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
function myMapFunction(doc) { | |
doc.equipments.forEach(function (equipment) { | |
emit(equipment.type); | |
}); | |
} |
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
db.query(myMapFunction, { | |
key: 'bolas', | |
include_docs: true | |
}).then(function (result) { | |
// got result | |
}); |
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
{ | |
"total_rows": 5, | |
"offset": 0, | |
"rows": [ | |
{ | |
"doc": "...", | |
"key": "bolas", | |
"id": "...", | |
"value": null | |
}, | |
{ | |
"doc": "...", | |
"key": "bolas", | |
"id": "...", | |
"value": null | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/28273588/querying-nested-objects-in-pouchdb