Skip to content

Instantly share code, notes, and snippets.

@telekosmos
Created October 14, 2015 18:27
Show Gist options
  • Save telekosmos/5e9b606e7aef6a2abe8d to your computer and use it in GitHub Desktop.
Save telekosmos/5e9b606e7aef6a2abe8d to your computer and use it in GitHub Desktop.
PouchDB querying nested objects
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',
}
]
}
];
function myMapFunction(doc) {
doc.equipments.forEach(function (equipment) {
emit(equipment.type);
});
}
db.query(myMapFunction, {
key: 'bolas',
include_docs: true
}).then(function (result) {
// got result
});
{
"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