def node_update(node, facts)
      logger.debug "  updating #{node}"
      connection[nodes_collection].find(_id: node).replace_one(facts,
        upsert: true,
        bypass_document_validation: true,
        check_keys: false,
        validating_keys: false)
    rescue ::Mongo::Error::OperationFailure => e
      logger.warn "  updating #{node} failed with: #{e.message}"
      # mongodb doesn't support keys with a dot
      # see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
      # as a dirty workaround we delete the document and insert it ;-)
      # The dotted field .. in .. is not valid for storage. (57)
      # .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.
      # (BSON::String::IllegalKey)
      raise e unless e.message =~ /The dotted field / || e.message =~ /is an illegal key/
      logger.warn "    we transform the dots into underline characters"
      begin
        facts = Hash[facts.map { |k, v| [k.tr('.', '_'), v] }]
        connection[nodes_collection].find(_id: node).replace_one(facts,
          upsert: true,
          bypass_document_validation: true,
          check_keys: false,
          validating_keys: false)
      rescue
        logger.error "  inserting node #{node} failed again with: #{e.message}"
      end
    end
def node_update(node, facts)
      logger.debug "  updating #{node}"
      connection[nodes_collection].find(_id: node).replace_one(facts,
        upsert: true,
        bypass_document_validation: true,
        check_keys: false,
        validating_keys: false)
    rescue ::Mongo::Error::OperationFailure => e
      logger.warn "  updating #{node} failed with: #{e.message}"
      # mongodb doesn't support keys with a dot
      # see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
      # as a dirty workaround we delete the document and insert it ;-)
      # The dotted field .. in .. is not valid for storage. (57)
      # .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.
      # (BSON::String::IllegalKey)
      raise e unless e.message =~ /The dotted field / || e.message =~ /is an illegal key/
      logger.warn "    we transform the dots into underline characters"
      begin
        facts = Hash[facts.map { |k, v| [k.tr('.', '_'), v] }]
        connection[nodes_collection].find(_id: node).replace_one(facts,
          upsert: true,
          bypass_document_validation: true,
          check_keys: false,
          validating_keys: false)
      rescue
        logger.error "  inserting node #{node} failed again with: #{e.message}"
      end
    end
update or insert facts for given node name

 @param node [String] node name
 @param facts [Hash] facts for the node