Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-631

Added support for the $slice operator

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I've added a type check to the processing of the :fields options to skip the addition of :_type to the fields list if :field is a hash. This should maintain the current behavior as well as provide support for the $slice operator, which requires that :fields be a hash, not an array.

      http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-RetrievingaSubrangeofArrayElements

      It is now possible to manipulate the range of subfields in a document. Compare the following:
      Service.last.service_logs.count
      => 66

      Service.all.extras(:fields => {:service_logs => {"$slice" => 10}}).last.service_logs.count
      => 10

            Assignee:
            Unassigned Unassigned
            Reporter:
            loginx Xavier Spriet
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: