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
Message from discussion where to use ensure_index ????

Received: by 10.58.132.238 with SMTP id ox14mr1931586veb.15.1348355489542;
        Sat, 22 Sep 2012 16:11:29 -0700 (PDT)
X-BeenThere: mongodb-user@googlegroups.com
Received: by 10.52.92.207 with SMTP id co15ls3481643vdb.5.gmail; Sat, 22 Sep
 2012 16:11:20 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.52.156.115 with SMTP id wd19mr1465132vdb.2.1348355480235; Sat,
 22 Sep 2012 16:11:20 -0700 (PDT)
Authentication-Results: ls.google.com; spf=pass (google.com: domain of
 alabdeloua...@gmail.com designates internal as permitted sender)
 smtp.mail=alabdeloua...@gmail.com; dkim=pass
 header...@gmail.com
Received: by s8g2000vbc.googlegroups.com with HTTP; Sat, 22 Sep 2012 16:11:20
 -0700 (PDT)
Date: Sat, 22 Sep 2012 16:11:20 -0700 (PDT)
In-Reply-To: <CALKyTE7h7ntQqyiupqFO6Stuuc0VLZOKAJRYhN2N-otmhbo=AQ@mail.gmail.com>
References: <66ba1d47-7358-4a00-a2e9-d8e67746ff42@o30g2000vbu.googlegroups.com>
 <CALKyTE6k2r-RF6U1XZuEOAyFD=sEJuVF-6ZR47sBy3rQaxsEpg@mail.gmail.com>
 <f8dec5e0-797d-4e52-80e8-541e7d30f4f6@d9g2000vbf.googlegroups.com> <CALKyTE7h7ntQqyiupqFO6Stuuc0VLZOKAJRYhN2N-otmhbo=AQ@mail.gmail.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 (KHTML, like
 Gecko) Chrome/16.0.912.77 Safari/535.7,gzip(gfe)
Message-ID: <7dc3c176-25d1-41ec-ac57-5ed99dc89d54@s8g2000vbc.googlegroups.com>
Subject: Re: where to use ensure_index ????
From: aliane abdelouahab <alabdeloua...@gmail.com>
To: mongodb-user <mongodb-user@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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:
> 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 ma=
de
> 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/q=
uestions/5912661/pymongo-mongodb-create-ind...
> could be helpful hopefully.
>
> On 22 September 2012 23:50, aliane abdelouahab <alabdeloua...@gmail.com>w=
rote:
>
>
>
>
>
>
>
> > pseudo will search for pseudo in database
>
> > pseudo =3D self.get_argument("pseudo")
> > pseudo =3D 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:
> > > 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.c=
om
> > >wrote:
>
> > > > hi, i've asked it on stackoverflow, and no answers, so i've said th=
at
> > > > maybe ensure_index is only done by the admininstrator with the shel=
l?
> > > > 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 wa=
y
> > > > to add it as a command and not embedded in a complete code:
>
> > > > If you want to add indexing to speed queries:
>
> > > > =A0 =A0 db.users.ensure_index(the_key)
>
> > > > So I tried to add it to a class:
>
> > > > =A0 =A0 class Registration(BaseHandler):
> > > > =A0 =A0 =A0 =A0 def post(self):
> > > > =A0 =A0 =A0 =A0 =A0 =A0 # do stuff to get user information using th=
e
> > > > self.get_argument()
> > > > =A0 =A0 =A0 =A0 =A0 =A0 user=3D{"all information":informations}
> > > > =A0 =A0 =A0 =A0 =A0 =A0 self.db.users.insert(user, w=3D1)
> > > > =A0 =A0 =A0 =A0 =A0 =A0 self.db.users.ensure_index(pseudo, commune)
>
> > > > But I get errors like this:
>
> > > > =A0 =A0 self.db.users.ensure_index(pseudo, commune)
> > > > =A0 =A0 =A0 =A0 =A0 File "build\bdist.win-amd64\egg\pymongo\collect=
ion.py", line
> > > > 829, in ensure_index
> > > > =A0 =A0 =A0 =A0 =A0 return self.create_index(key_or_list, cache_for=
, **kwargs)
> > > > =A0 =A0 =A0 File "build\bdist.win-amd64\egg\pymongo\collection.py",=
 line
> > > > 740, in create_index
> > > > =A0 =A0 =A0 =A0 self.__name, name, cache_for)
> > > > =A0 =A0 =A0 File "build\bdist.win-amd64\egg\pymongo\connection.py",=
 line
> > > > 330, in _cache_index
> > > > =A0 =A0 =A0 =A0 expire =3D datetime.timedelta(seconds=3Dcache_for) =
+ now
> > > > =A0 =A0 TypeError: unsupported type for timedelta seconds component=
:
> > > > unicode
>
> > > > And I guess it will be the same tip when using inserting a sub-
> > > > document:
>
> > > > =A0 =A0 self.db.users.update({"email":email}, {"$push":{"produit_up=
":
> > > > {"id":id, "namep":namep, "nombre":nombre}}})
> > > > =A0 =A0 self.db.users.ensure_index("product_up.namep") #????
>
> > > > any clues?
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "mongodb-user" group.
> > > > To post to this group, send email to mongodb-user@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > mongodb-user+unsubscribe@googlegroups.com
> > > > See also the IRC channel -- freenode.net#mongodb
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb