The getDocumentByKey method only returns the first document of the view matching your key.
If you want to use a collection, use getAllDocumentsByKey. note that the results you’ll get won’t be view sorted. Read the help for further information on this.
Choosing between getDocumentByKey, getAllDocumentsByKey and GetAllEntriesByKey depend on what you need.
All of these solutions will give you the possibility to find the documents you’re looking for.
With getDocumentByKey, you get the first document corresponding to the key. From this point, you might then navigate to the next one (following order view) until some criteria is met.
With getAllDocumentsByKey you get an unsorted document collection with only the documents responding to the key.
with getEntriesByKey you get a view sorted collection of document entries. This solution requires you to write a bit more code… but this method is quite efficient, because view entries are cached in memory.
What do you really need? If you need to get the documents regardless of the order, go for getAllDocumentsByKey. If order matter, then choose between getDocumentByKey (combined with a getNextDocument) and getAllEntriesByKey.