Chapter 5 Quiz 1L sort() and limit()

Hi all

I selected the correct two answers, plus an additional one. The additional answer I selected did not filter on null values, but I selected it because I tested the query first and it returned the correct results. The answer suggests that a sort() will cause null values to be the smallest value, as they will be included in the cursor, but this didn’t happen for me. Could someone please explain what the default behaviour should be?


You could have been using the wrong database, or collection. When using the correct data set I get:

db.companies.find( {}, { founded_year : 1}  ).sort( { "founded_year" : 1 }).limit( 5 )
{ _id: ObjectId("52cdef7c4bab8bd675297dd6"),
  founded_year: null }
{ _id: ObjectId("52cdef7c4bab8bd675297db0"),
  founded_year: null }
{ _id: ObjectId("52cdef7c4bab8bd675297e16"),
  founded_year: null }
{ _id: ObjectId("52cdef7c4bab8bd675297dfa"),
  founded_year: null }
{ _id: ObjectId("52cdef7c4bab8bd675297da6"),
  founded_year: null }

Thanks Steve - I must have made an error somewhere!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.