Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
where to use ensure_index ????
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
aliane abdelouahab  
View profile  
 More options Sep 22 2012, 6:17 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sat, 22 Sep 2012 15:17:31 -0700 (PDT)
Local: Sat, Sep 22 2012 6:17 pm
Subject: where to use ensure_index ????
hi, i've asked it on stackoverflow, and no answers, so i've said that
maybe ensure_index is only done by the admininstrator with the shell?
and not when the client clic somewhere!
here is the original question:

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") #????

any clues?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Sep 22 2012, 6:43 pm
From: Sam Millman <sam.mill...@gmail.com>
Date: Sat, 22 Sep 2012 23:43:11 +0100
Local: Sat, Sep 22 2012 6:43 pm
Subject: Re: [mongodb-user] where to use ensure_index ????

I saw this question. I think you have a error in your code personally.

What do pseudo and commune equal in your app as you go to call the
ensureIndex() function?

On 22 September 2012 23:17, aliane abdelouahab <alabdeloua...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 22 2012, 6:50 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sat, 22 Sep 2012 15:50:43 -0700 (PDT)
Local: Sat, Sep 22 2012 6:50 pm
Subject: Re: where to use ensure_index ????
pseudo will search for pseudo in database

pseudo = self.get_argument("pseudo")
pseudo = db.find({"pseudo":pseud})
and the same for commune, and there is other parameters, but because
those one are the searched fields later...

so if i put it under where i tell mongodb to store the user
information, then, everytime one added a new users, the index will be
stored? then it will be not good for write performances?

On 22 sep, 23:43, Sam Millman <sam.mill...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Sep 22 2012, 7:05 pm
From: Sam Millman <sam.mill...@gmail.com>
Date: Sun, 23 Sep 2012 00:05:42 +0100
Local: Sat, Sep 22 2012 7:05 pm
Subject: Re: [mongodb-user] Re: where to use ensure_index ????

Not sure since if it worked like that it would recreate the b-tree index
for all rows all over again. So I would probably say no.

I think you might have the wrong idea of what ensureIndex is. It is much
like in SQL where you create an index on a field. An index can only be made
once (unless it is removed then remade ofc) nad multiple calls to
ensureIndex defining the same index will be classed as no-ops (basically
ops that dont run).

Here is a SO question on how to ue ensureIndex:
http://stackoverflow.com/questions/5912661/pymongo-mongodb-create-ind...
could be helpful hopefully.

On 22 September 2012 23:50, aliane abdelouahab <alabdeloua...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 22 2012, 7:11 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sat, 22 Sep 2012 16:11:20 -0700 (PDT)
Local: Sat, Sep 22 2012 7:11 pm
Subject: Re: where to use ensure_index ????
so as from i understand, it's a work made by the administrator (from a
separated interface that a client cant get), so like that, he can do
it once a month for example?

On 23 sep, 00:05, Sam Millman <sam.mill...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Sep 22 2012, 7:18 pm
From: Sam Millman <sam.mill...@gmail.com>
Date: Sun, 23 Sep 2012 00:18:01 +0100
Local: Sat, Sep 22 2012 7:18 pm
Subject: Re: [mongodb-user] Re: where to use ensure_index ????

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,

On 23 September 2012 00:11, aliane abdelouahab <alabdeloua...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 22 2012, 7:20 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sat, 22 Sep 2012 16:20:11 -0700 (PDT)
Local: Sat, Sep 22 2012 7:20 pm
Subject: Re: where to use ensure_index ????
i got it, so what i do, is, making the indexes once just after
launching the application, so i'll index fields that a user will
search.
thank you :)

On 23 sep, 00:18, Sam Millman <sam.mill...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Millman  
View profile  
 More options Sep 22 2012, 7:23 pm
From: Sam Millman <sam.mill...@gmail.com>
Date: Sun, 23 Sep 2012 00:23:34 +0100
Local: Sat, Sep 22 2012 7:23 pm
Subject: Re: [mongodb-user] Re: where to use ensure_index ????

Exactly :) Np glad to have helped

On 23 September 2012 00:20, aliane abdelouahab <alabdeloua...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bernie Hackett  
View profile  
 More options Sep 23 2012, 12:39 am
From: Bernie Hackett <ber...@10gen.com>
Date: Sun, 23 Sep 2012 00:39:04 -0400
Local: Sun, Sep 23 2012 12:39 am
Subject: Re: [mongodb-user] where to use ensure_index ????

> self.db.users.ensure_index(pseudo, commune)

Not sure what "commune" is here but the second parameter to
ensure_index is the length of time in seconds that the index is cached
client side. Given the error message I assume "commune" is not an
integer. The documentation for ensure_index is here:

http://api.mongodb.org/python/current/api/pymongo/collection.html#pym...

On Sat, Sep 22, 2012 at 6:17 PM, aliane abdelouahab


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 23 2012, 5:26 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sun, 23 Sep 2012 02:26:05 -0700 (PDT)
Local: Sun, Sep 23 2012 5:26 am
Subject: Re: where to use ensure_index ????
ah ok! now i can learn the ensure_index now that you helped me to
understand the utility of this function ;)
thank you again

On 23 sep, 05:39, Bernie Hackett <ber...@10gen.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »