So I have a mongo collection with an array of chapters
inside it.
What I want to do is do a find, sorted by date - but push all the documents that have only 1 chapter to the end of the list.
Note: I don't want to sort by chapters count - only push the 1 chapter documents to the end of the cursor.
Now I could do 2 finds:
cursor1 = collection.find({'chapters.1':{$exists: true}})
//iterate over it
cursor2 = collection.find({'chapters.1':{$exists: false}})
//iterate over it
The problem is - I'm doing pagination. Currently without the seperation is:
(sorry for pseudocode - translating from PHP)
cursor = collection.find()
cursor.sort({created: -1})
cursor.skip($page * $page_size)
cursor.limit($page_size);
When trying the above solution to separate - it creates quite a nasty code
Do I have a choice? Any magic "push 1 chapters to the end" to push into the find itself?