A while back I sent a question to the list about only returning the most recent version of a document, based on a numerical version field stored in each record. Someone suggested that I use field collapsing to do so, and in most cases it seems to work well. However, I've hit a snag and I'd appreciate it if anyone could offer some pointers.
At the moment, my scheme looks roughly like this (not using exact data types): contents : string documentId : string version: float When I query on contents, I can use field collapsing to group by documentId, only return one instance of documentId, and sort each group by version in descending order. If the newest version of the document is returned by the query, everything works great. What I've realized, though, is that using field collapsing doesn't necessarily get me the most recent version of the document, if it matches the query, but the most recent version of any document that matches the query. Is there any good way to get the most recent version of the document that matches the query, but only if it's the record with the highest version number? For example, with the following record set: contents: angry horse documentId: 1a version: 1.0 contents: distraught horse documentId: 1a version: 1.1 contents: peevish horse documentId: 1a version: 2.0 Searching for "horse" will return version 2.0 of 1a using collapsing in the manner that I described above. If I search for "angry", I'll get back version 1.0 of 1a. I'd rather get back nothing at all. Is this possible?