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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:11:56+00:00 2026-06-11T20:11:56+00:00

How can I add an index in production code? I have found only the

  • 0

How can I add an index in production code? I have found only the way to add it as a command and not embedded in a complete code:

If you want to add indexing to speed queries:

db.users.ensure_index(the_key)

So I tried to add it to a class:

class Registration(BaseHandler):
    def post(self):
        # do stuff to get user information using the self.get_argument()
        user={"all information":informations}
        self.db.users.insert(user, w=1)
        self.db.users.ensure_index(pseudo, commune)

But I get errors like this:

self.db.users.ensure_index(pseudo, commune)
      File "build\bdist.win-amd64\egg\pymongo\collection.py", line 829, in ensure_index
      return self.create_index(key_or_list, cache_for, **kwargs)
  File "build\bdist.win-amd64\egg\pymongo\collection.py", line 740, in create_index
    self.__name, name, cache_for)
  File "build\bdist.win-amd64\egg\pymongo\connection.py", line 330, in _cache_index
    expire = datetime.timedelta(seconds=cache_for) + now
TypeError: unsupported type for timedelta seconds component: unicode

And I guess it will be the same tip when using inserting a sub-document:

self.db.users.update({"email":email}, {"$push":{"produit_up":{"id":id, "namep":namep, "nombre":nombre}}})
self.db.users.ensure_index("product_up.namep") #????
  • 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-11T20:11:57+00:00Added an answer on June 11, 2026 at 8:11 pm

    got the answer:

    No No, ensureIndex is the same as creating an index. It does nothing
    special, maybe the name of the function is a little odd really and should
    be called create_index instead.
    Since Mongo has no pre-defined schema (NoSQL) it has to create indexes a
    different way to SQL. The way proposed was through client side when the
    user decides they need an index on a particular field. This is how
    collections and what not are created, when they are used by the client.
    This function was called ensureIndex().
    So there is only one call needed to ensureIndex() within your app and it
    should be a list of fields for that index as the first param and any extra
    options (like sparse) for the second param.
    There is no work needed by the administrator to keep this index intact,
    well not once a month but if something fails in the cluster then yea, some
    work will be needed by the admin to possibly remake the index.
    I personally have a file of indexes I call everytime my app is loaded.
    I hope this clears things up a little,

    answer from Google groups

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

Sidebar

Related Questions

The Zend project creates URLs like: http://localhost/zftest/public/index/add How can I have a URL like
While we can add Inline Images in paragraphs there does not appear to be
How can I add index to an 18 GB innodb mysql table without affecting
So, ok. I have many php files and one index.php file. All files can't
How can I add an index, to input names and ids in forms that
I am attempting to code a very simple way for a user to add
I have such code, for making chain selects in my form View for index
How can i read only one record, when i want all records its fine
Can I add an INDEX to a Common Table Expression (CTE)?
I can add and remove the last line in my dynamic form and calculate

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.