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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:28:13+00:00 2026-05-26T09:28:13+00:00

When I call ensureIndex from the mongo shell on a collection for a compound

  • 0

When I call ensureIndex from the mongo shell on a collection for a compound index an _id field of type ObjectId is auto-generated in the index object.

> db.system.indexes.find();
{ "name" : "_id_", "ns" : "database.coll", "key" : { "_id" : 1 } }
{ "_id" : ObjectId("4ea78d66413e9b6a64c3e941"), "ns" : "database.coll", "key" : { "a.b" : 1, "a.c" : 1 }, "name" : "a.b_1_a.c_1" }

This makes intuitive sense as all documents in a collection need an _id field (even system.indexes, right?), but when I check the indexes generated by morphia’s ensureIndex call for the same collection *there is no _id property*.

Looking at morphia’s source code, it’s clear that it’s calling the same code that the shell uses, but for some reason (whether it’s the fact that I’m creating a compound index or indexing an Embedded document or both) they produce different results. Can anyone explain this behavior to me?

  • 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-26T09:28:14+00:00Added an answer on May 26, 2026 at 9:28 am

    Not exactly sure how you managed to get an _id field in the indexes collection but both shell and Morphia originated ensureIndex calls for compound indexes do not put an _id field in the index object :

    > db.test.ensureIndex({'a.b':1, 'a.c':1})
    > db.system.indexes.find({})
    { "v" : 1, "key" : { "_id" : 1 }, "ns" : "test.test", "name" : "_id_" }
    { "v" : 1, "key" : { "a.b" : 1, "a.c" : 1 }, "ns" : "test.test", "name" : "a.b_1_a.c_1" }
    >
    

    Upgrade to 2.x if you’re running an older version to avoid running into now resolved issues. And judging from your output you are running 1.8 or earlier.

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

Sidebar

Related Questions

I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I call a certain div from another page with jquery to be loaded into
I call an ajax enabled wcf service method , <script type=text/javascript> function GetEmployee() {
Call to a member function save() on a non-object in .../views/manufacturer/tmpl/edit.php line 24 which
I call a template like this from my view: return render_to_response('mytemplate.html', context_instance=RequestContext(request)) I'm trying
i call a controller action in a unit test. ViewResult result = c.Index(null,null) as
We use MongoDB to collect logs on pageviews. $collection_name = logs..date('Y')...date('m')...date('d'); $collection = $this->Mongo->$collection_name;
Call me crazy, but I'm the type of guy that likes constructors with parameters
I call a piece of an unmanaged C++ code from my C# application to
I call a Python script from crontab. The script does generates colored output using

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.