createIndexes triggers operations while the indexes already exists

Im having an issue while trying to create indexes that already exists.
My scenario is that i have a service that every time it resets, it trying to create indexes.
From what i’ve read on MongoDB documentation, it should not recreate it. When i tried it, i saw that our Mongo servers got lots of “CreateIndexes” commands when i issued db.currentOp() and it impacted the performance of our server. I wonder why it still tries to create the indexes and if there is something i can do to solve it? We are using python with pymongo to trigger the CreateIndexes command.

When i saw the commands when used db.currentOp(), i saw that all of the commands had $truncated before them, couldn’t find something about it, what does it mean?

Hi @Ronen_Zolicha and welcome to the MongoDB community forum!!

Yes, you are right. Starting from MongoDB version 2.0, the db..createIndex() would not recreate the indexes provided the field name on the index are same.
However please note that, the issuing the createIndex on the same field would not result with an error log message.

To understand the issue in more detail, could you share the following information:

  1. The code that you are trying to use in your application.
  2. The output for db.currentOp()
  3. The logs messages that you are observing.
  4. The MongoDB version and the pymongo version you are using.

Could you also help in understanding, what does the reset operation does in your service?

Let us know if you have any further queries.

Best Regards

Hey Aasawari,

I’m using python 3.6
Mongo version is 4.2
Pymongo version 3.12.3

  1. The code I’m trying to do is Pymongo’s create_indexes

  2. The response from db.currentOp() is showing the create_index command

  3. When i’m calling to create_indexes, the call is waiting for response and it won’t get it till the mongo server will finish to scan the collection. I’m not sure why it scans the collection because this specific index is already exists.

Im attaching one photo which contains all of the info since i cant attach more than one because i’m new here.

i looked into it more and more and found that one of the indexes passed with wrong name and everything seems fine. Thanks for the help :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.