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

  • Home
  • SEARCH
  • 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 948783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:18:00+00:00 2026-05-15T23:18:00+00:00

Could I declare a model with a key called :key , for instance? Is

  • 0

Could I declare a model with a key called :key, for instance? Is there any word I can’t use for a key?

  • 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-15T23:18:00+00:00Added an answer on May 15, 2026 at 11:18 pm

    The first question if very easy to answer yourself. Open irb and try:

    >> require 'mongo_mapper'
    => true
    >> MongoMapper.database = 'test'
    => "test"
    >> class Test
    >>   include MongoMapper::Document
    >>   key :key
    >>   end
    => #<MongoMapper::Plugins::Keys::Key:0x101fc7a90 @default_value=nil, @type=nil, @name="key", @options={}>
    >> t = Test.new(:key => 'value')
    => #<Test _id: BSON::ObjectID('4c4dcced7123374587000001'), key: "value">
    >> t.save
    => true
    >> Test.all
    => [#<Test _id: BSON::ObjectID('4c4dcced7123374587000001'), key: "value">]
    

    No errors? I guess key is a valid key!

    As far as I know, the only keys you shouldn’t use for your own data are _id and _type. You can use either, but they will change behavior. Using _id will make whatever you’re setting as that key the unique id for the object. Using _type will cause MongoMapper to try to instantiate an instance of whatever’s in your _test key when bringing the object back from the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unhelpful error message, but this is because the input tree… May 17, 2026 at 2:18 am
  • Editorial Team
    Editorial Team added an answer You can definitely do that, just import it as usual.… May 17, 2026 at 2:18 am
  • Editorial Team
    Editorial Team added an answer %~dp0 will be the directory. Here's some documentation on all… May 17, 2026 at 2:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there any reason why I could (or should) not declare dependency properties as
In my User model I could have: has_many :tasks and in my Task model:
I need to create a trigger in every database on my sql 2005 instance.
I am about to start a large Django project at work. And the key
I have a sql query with 50 parameters, such as this one. DECLARE @p0
I am trying to use NHibernate to map a legacy database which uses a
I have a Comment class with a :foreign_key of post_id in the Post class.
I'm trying to Entitify some external table (which I don't administer) in order to
I'm getting the following error when I run ./manage.py reset app1 : Error: Error:
I'm refactoring a number of modules in an Excel 2003 workbook and the same

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.