require 'database_cleaner/moped/base'
require 'database_cleaner/generic/truncation'

module DatabaseCleaner
  module Moped
    module TruncationBase
      include ::DatabaseCleaner::Moped::Base
      include ::DatabaseCleaner::Generic::Truncation

      def clean
        if @only
          collections.each { |c| session[c].find.remove_all if @only.include?(c) }
        else
          collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
        end
        true
      end

      private

      def collections
        if db != :default
          session.use(db)
        end

        session.command(listCollections: 1)['cursor']['firstBatch'].map do |collection|
          collection['name']
        end
        .reject do |collection_name|
          collection_name =~ /\.system\.|\$/
        end
      end

    end
  end
end

require 'database_cleaner/moped/base'
require 'database_cleaner/generic/truncation'

module DatabaseCleaner
  module Moped
    module TruncationBase
      include ::DatabaseCleaner::Moped::Base
      include ::DatabaseCleaner::Generic::Truncation

      def clean
        if @only
          collections.each { |c| session[c].find.remove_all if @only.include?(c) }
        else
          collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
        end
        true
      end

      private

      def collections
        if db != :default
          session.use(db)
        end

        session.command(listCollections: 1)[:cursor][:firstBatch].map do |collection|
          collection[:name]
        end.reject do |collection_name|
          collection_name =~ /system|\$/
        end
      end

    end
  end
end

--- 
+++ 
@@ -23,10 +23,11 @@
           session.use(db)
         end
 
-        session.command(listCollections: 1)[:cursor][:firstBatch].map do |collection|
-          collection[:name]
-        end.reject do |collection_name|
-          collection_name =~ /system|\$/
+        session.command(listCollections: 1)['cursor']['firstBatch'].map do |collection|
+          collection['name']
+        end
+        .reject do |collection_name|
+          collection_name =~ /\.system\.|\$/
         end
       end
 
Use string as keys to read the collections data structure
Fix regexp to skip system collections
