Database Reference
In-Depth Information
5.3. Dealing with more than one match
Inthepreviousexample,youindexedthe email propertyforeachuser,and,assumingthat
email addresses are unique, you expected a single result from the index lookup operation.
Thatwon'talwaysbethecase.Let'saddanotherindexedpropertytotheusernodes— age .
Naturally, multiple user nodes can have the same value for the age property. The key in
such an index can reference multiple user nodes as values, as figure 5.3 illustrates.
Figure 5.3. User nodes indexed by the age property, with each key potentially referencing multiple nodes
Earlier, we assumed that you'd always find at most one match for the provided user email
address.Ifthat'snotgoingtobethecase,you'llneedtoiterateovertheindexhitsreturned,
as shown in the following listing, which retrieves all users who are 34.
Listing 5.3. Iterating through multiple results of an index lookup operation
 
Search WWH ::




Custom Search