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 7860055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:08:18+00:00 2026-06-02T22:08:18+00:00

While I undertand a foreign key constraint would not make sense for a NoSql

  • 0

While I undertand a foreign key constraint would not make sense for a NoSql database, should it not ensure that it updates the indexes if it allows me to rename fields?
http://www.mongodb.org/display/DOCS/Updating#Updating-%24rename

{ $rename : { old_field_name : new_field_name } }

but if I had

db.mycollections.ensureIndex({old_field_name:1});

wouldn’t it be great if the index was updated automatically?

Is it that since system.indexes is simply just another table and such a automatic update would imply a foreign key constraint of sorts, the index update is not done? Or am I missing certain flags?

  • 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-06-02T22:08:19+00:00Added an answer on June 2, 2026 at 10:08 pm

    Quoting Mike O’ Brien:

    The $rename operator is analogous to doing a $set/$unset in a single atomic operation. It’s a shortcut for situations where you need to take a value and move it into another field, without the need to do it in 2 steps (one to fetch the value of the field, another to set the new one).

    Doing a $rename does mean the data is changing. If I use $rename to rename a field named “x” to “y”, but the field named “y” already existed in the document, the old value for “y” is overwritten, and the field “x” will no longer exist anymore. If either “x” or “y” is indexed, then the operation will update those indexes to reflect the final values resulting from the operation. The same applies when using rename to move a field from within an embedded document up to the top level (e.g. renaming “a.b” to “c”) or vice versa.

    The behavior suggested in the SO question (i.e., renaming a field maintains the relationship between the field it was moved to and its value in the index) then things can get really confusing and make it difficult to reason about what the “correct” expected behavior is for certain operations. For example, if I create an index on field “A” in a collection, rename “A” to “B” in one of the documents, and then do things like:
    update({“A” : }, {“$set”:{“B”:}}) // find a document where A= and set its value of B to
    update({“B” : }, {“$set”:{“A”:}}) // find a document where B= and set its value of A to

    Should these be equivalent?
    In general, having the database maintain indexes across a collection by field name is a design decision that keeps behavior predictable and simple.

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

Sidebar

Related Questions

A while ago, I came to the realization that a way I would like
While reading this link, I did not understand the point on avoiding table locks
While I understand that sealed can be used for security reasons, a few people
While I understand a little about currying in the mathematical sense, partially applying an
What's the best practice for filtering based on a foreign key's property in a
While I understand that in order for an iPhone application to be accepted on
For a while, I've been told by a number of people that a listing
While I understand this question is fairly vague since I'm not giving you all
I'm doing some maintenance work on a database application and I've discovered that, joy
While I understand what simulation and emulation mean in general, I almost always get

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.