Analysis and Optimization of an N+1 Scenario in Mongoid

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • rubygems

    Library packaging and distribution for Ruby.

  • # # mongoid_n_plus_1.rb # require 'benchmark' require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'mongoid' gem 'mongo' end Mongoid.configure do |config| config.clients.default = { uri: "mongodb://localhost:27017,localhost:27018,localhost:27019/test" } end class Test include Mongoid::Document field :name, type: String # return all entries from the document that aren't defined as Mongoid fields def entries attr = self.attributes.dup attr.delete_if { |k, v| self.fields.key?(k) } attr.sort end def compact! # unset each field that doesn't belong to the Mongoid document as an # explicitly defined field self.entries.each do |entry| self.unset entry.first end end end

  • bullet

    help to kill N+1 queries and unused eager loading

  • To address this Rails offers Eager Loading Associations and there are gems (such as bullet) that can be used to detect the N + 1 pattern in an application.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • m

    mongodb version management

  • First, we spin up a local replica set using some open source MongoDB helper utilities (see m and mtools):

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts