Skip to content

Nested fields. #2986

Answered by rjharmon
hamiltonsalazar asked this question in Q&A
Jul 7, 2020 · 4 comments · 3 replies
Discussion options

You must be logged in to vote

You're right, one sometimes has to piece together bits from different places to arrive at working results for a specific case.

Here's an example of a map & reduce for indexing attributes {id, name} in an array of THINGS in some documents. These attributes need to be included in a design-doc view.

{
  map: function(doc) {
    if (doc.type === "widget" && doc.THINGS) {
      for (var i=0; i<doc.THINGS.length; i++) {
        var thing = doc.THINGS[i];
        emit([thing.id, thing.name], 1);
      }
    }
  },
  reduce: "_count",
...
}

Querying it based on some thingId could use view-querying options such as those shown here, with the unicode character indicating a hard end to the key range.

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@hamiltonsalazar
Comment options

@wohali
Comment options

wohali Jul 7, 2020
Collaborator

Comment options

You must be logged in to vote
1 reply
@hamiltonsalazar
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by janl
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants