Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:59:55+00:00 2026-05-23T16:59:55+00:00

Well, the title is self-explicative. But, let me elaborate a little better. First of

  • 0

Well, the title is self-explicative. But, let me elaborate a little better.
First of all, I am using Mongoid, a Gem for using MongoDB with rails applications.

#1) I have a large collection, which has information about a map. A map embeds a lot of tiles, and each tile references a terrain collection, a user collection, and has some other information. Therefore, if I obtain all tiles from a map, I will have a really large structure. However, I would like to cache a structure that comprises a matrix with only the terrain information. In order to do that, I select all tiles (and hence, all their unneeded information) and use only the terrain field. How can I select ONLY the terrain field on Mongoid? I tried operating with select on several ways, but I did not manage to do it.. (by the way, just for the sake of exemplification, I access the tiles array with the line “Map.first.tiles”).

#2) Well.. I am already here, so, why not ask this. Should I really use the inverse_of fields on my Models? I did not use it anywhere, and everything seems to be working perfectly. I do not see why it is needed, as it is pretty much straight forward to determine where to put them, and what they are the inverse of.

Thanks in advance.
Fernando.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:59:56+00:00Added an answer on May 23, 2026 at 4:59 pm

    In general, to only select 1 or more attributes in a mongoid query:

    Map.only(:name).all
    

    I wouldn’t bother with inverse_only except when Mongoid needs help figuring out the classes. In general, not needed.

    If you need to only return certain attributed on an embedded document, you’ll want to use the full-path:

    Map.first.tiles
     => [#<Tile _id: 4e1e486042f5bc06e7000002, name: "Earth", distance: 34>]
    
    Map.only("tiles.name").first.tiles
     => [#<Tile _id: 4e1e488742f5bc06e7000003, name: "Earth", distance: nil>]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, the title is pretty much self-explanatory. I've seen Quantian , but it's pretty
Well the question title may not be self explanatory, so let me go ahead
Well the title is quite self explanatory. I want to build two panels one
Well, title self describes it.. I need to run a sql function to clean
The title explains it pretty well, but I'm trying to build a 'for loop'
My title sums this up pretty well. My first though it to provide a
Well, question is in title. Is it possible at all? I can use css
Well the title speaks for it self. I suspect it has to do with
Well, the title is quite self-explanatory... Is it possible to set default port number
Well the title is self explanatory. What will be the python code equivalent to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.