docpadquery-engine

How to query on nested metadata with Docpad's query-engine


As an example, I have a document with nested custom metadata like:

owner: {"id":"12345"}

I've tried to find this document with:

docpad.getCollection("documents").findAll({
    "owner.id": "12345"
});

but to no avail.

What have I done wrong?


Solution

  • Nested queries aren't supported by default, as it is a tricky thing to do.

    For now, you should be able to do this:

    CoffeeScript:

    docpad.getCollection("documents").findAll({
        "owner": ({id}) -> id is "12345"
    })
    

    JavaScript:

    docpad.getCollection("documents").findAll({
        "owner": function(model){ return model.id === "12345" }
    })