Mongoid allows one to query both references and embedded documents using methods like find_by
or where
.
Say I have a model, Project
, which embeds many Tasks
. When I want to find a specific task, I am currently performing the following operation:
project = Project.find(...)
task = project.tasks.find_by(:some_field => 'Some Value')
My question is this, does the find_by
query on the embedded tasks above issue another query to the Mongo database, or does it recognize that tasks are embedded in the given project and instead filter the tasks locally?
Thank you
Nope, it does not do another query.
Embedded documents are basically denormalized. http://docs.mongodb.org/manual/core/data-model-design/#data-modeling-embedding
If you are interested in seeing the queries yourself, you can turn it on: How can I see raw mongoDB queries with Mongoid
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.