def as_json(options = nil)
      if options && (options[:compact] == true)
        super(options).reject! { |k,v| v.nil? }
      else
        super(options)
      end
    end
def as_json(options = nil)
      if options && (options[:compact] == true)
        super(options).reject! { |k,v| v.nil? }
      else
        super(options)
      end
    end
Calls #as_json on the document with additional, Mongoid-specific options.

 @note Rails 6 changes return value of as_json for non-primitive types
   such as BSON::ObjectId. In Rails <= 5, as_json returned these as
   instances of the class. In Rails 6, these are returned serialized to
   primitive types (e.g. {"$oid"=>"5bcfc40bde340b37feda98e9"}).
   See https://github.com/rails/rails/commit/2e5cb980a448e7f4ab00df6e9ad4c1cc456616aa
   for more information.

 @example Get the document as json.
   document.as_json(compact: true)

 @param [ Hash ] options The options.

 @option options [ true, false ] :compact Whether to include fields with
   nil values in the json document.

 @return [ Hash ] The document as json.

 @since 5.1.0