I have the following query for getting an actor, roles and movies from the example movie database in Neo4j like this:

MATCH (actor:Person {name:"Meg Ryan"})-[role:ACTED_IN]-&gt;(movies)
RETURN actor, collect({roles: role.roles, movies: movies}) as movies


It all works nice, but when I want to order the collection by movies release year, I'm encountering some issues. 

I tried to do it like this: 

MATCH (actor:Person {name:"Meg Ryan"})-[role:ACTED_IN]-&gt;(movies)
ORDER BY movies.released DESC
RETURN actor, collect({roles: role.roles, movies: movies}) as movies


but i get this error: 

Invalid input 'R': expected 'p/P' (line 2, column 2)
"ORDER BY movies.released DESC"
  ^


How can i order the collection by the Movies release year before putting it in a collection?


Question: What is the best way for a user to select an item by unique identifier?
Answer: Well, if you can do this using barcode OR manual input, and you say serial numbers are sequential, so both teh barcode AND teh serial numbers will have common characters, you can do something like this:

1- Offer the user to scan the barcode (include some hint message)
   1.1 - If user scans barcode
      1.1.1 - on success --&gt; stop
      1.1.2 - on failure --&gt; goto 2
2- Offer the user to manually input the value. Here you can ask to enter barcode or SN number. Strip all common elements and ask your user to input the values that are not common. 
    2.1- If sequentially generated series: ask to enter the last 3, 4, 5 numbers (based on the pattern structure of your serial number)
    2.2- If barcode number, you'll have quite some common numbers. For example, on UPC based barcodes, you'll probably need to ask for the last 4 numbers
3- Validate and provide instant feedback
    3.1 - If correct, stop process and display success message
    --else
    3.2 - Ask user to correct input, go to 3


Sorry about the very basic explanation, but hope it's enough to understand the idea