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

Exception will exit the Rails app, how to avoid it ?

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

      I got {{ 'Client Error: Remaining data too small for BSON object'}}
      This is buggy code {{ model.collection.insert(@data_in_chunk)}}

      So I tried to use Begin Rescue to ignore the exception, but it didn't work.
      How could I ignore the error from Mogoid

      Error message

      Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
      @length=97
      @request_id=10246
      @response_to=0
      @op_code=2004
      @flags=[]
      @full_collection_name="tw_development.$cmd"
      @skip=0
      @limit=-1
      @selector={:getlasterror=>1, :w=>1}
      @fields=nil>
      failed with error 10304: "Client Error: Remaining data too small for BSON object"

      Exceptinal code

      def bulk_insert_to_collection(collection_name)
      model = collection_name.capitalize.constantize.new
      begin
      model.collection.insert(@data_in_chunk)
      rescue Exception => e
      @@mongo_logger.error("File #

      {@file_path}

      : line of #

      {i}

      #

      {Time.now}

      ")
      end
      @data_in_chunk = []
      end

      collection status

      > db.cds.stats()
      {
      "ns" : "tw__development.cds",
      "count" : 45214787,
      "size" : 91876447184,
      "avgObjSize" : 2032,
      "numExtents" : 64,
      "storageSize" : 93016583552,
      "lastExtentSize" : 2146426864,
      "paddingFactor" : 1,
      "paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
      "userFlags" : 1,
      "capped" : false,
      "nindexes" : 1,
      "totalIndexSize" : 1946730128,
      "indexSizes" :

      { "_id_" : 1946730128 }

      ,
      "ok" : 1
      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            poc7667 poc7667
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: