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 = Mongo::Connection.new('localhost', Mongo::Connection::DEFAULT_PORT, :logger => Logger.new(STDOUT)).db('test_db') config.identity_map_enabled = true end class TestDocument include Mongoid::Document end # clear the test document collection TestDocument.collection.drop # add two new documents 2.times { TestDocument.new.save } # pull the ids ids = TestDocument.all.distinct(:_id) # run the test queries logger.info "Group find." TestDocument.find(ids) logger.info "Single find." TestDocument.find(ids.first) logger.info "Same group find." TestDocument.find(ids)