Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


identity map is never consulted by multi-id finders #1849

ghost opened this Issue · 1 comment

2 participants

Hans Hasselberg Durran Jordan
Deleted user

It seems like mongoid's Model.find command does not consult the identity map before querying the database for documents with IDs in a list. It correctly saves the resulting documents in the identity map, which is consulted before generating single-ID queries, but future multi-ID queries hit the database intact. I gather this is particularly impactful when Model.includes is used.

Below is a code sample that will reproduce the issue. Thanks!

require "rubygems"
require "mongoid"

Mongoid.configure do |config|
 config.master ='localhost', Mongo::Connection::DEFAULT_PORT, :logger =>'test_db')
 config.identity_map_enabled = true

class TestDocument
  include Mongoid::Document

# clear the test document collection

# add two new documents
2.times { }

# pull the ids
ids = TestDocument.all.distinct(:_id)

# run the test queries "Group find."
TestDocument.find(ids) "Single find."
TestDocument.find(ids.first) "Same group find."
Hans Hasselberg

Hello @rcbth,

thanks for reporting. I can see what you mean and I'll have a look.

Durran Jordan durran closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.