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:
> 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:
> --
> 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
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:
> 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:
> > 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:
> > --
> > 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
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).
> 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:
> > 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:
> > > 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:
> > > --
> > > 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
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 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).
> On 22 September 2012 23:50, aliane abdelouahab <alabdeloua...@gmail.com>wrote:
> > 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:
> > > 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:
> > > > 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:
> > > > --
> > > > 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
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:
> 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
> 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).
> > On 22 September 2012 23:50, aliane abdelouahab <alabdeloua...@gmail.com
> >wrote:
> > > 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:
> > > > 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:
> > > > > 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)
> > > > > --
> > > > > 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
> --
> 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
> 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:
> > 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
> > 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).
> > > On 22 September 2012 23:50, aliane abdelouahab <alabdeloua...@gmail.com
> > >wrote:
> > > > 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:
> > > > > 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?
> > > > > > 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)
> > > > > > --
> > > > > > 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
> > --
> > 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
> 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:
> > 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:
> > > 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
> > > 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).
> > > > On 22 September 2012 23:50, aliane abdelouahab <
> alabdeloua...@gmail.com
> > > >wrote:
> > > > > 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:
> > > > > > 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?
> > > > > > > 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)
> > > > > > > --
> > > > > > > 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
> > > --
> > > 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
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:
<alabdeloua...@gmail.com> wrote:
> 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:
> --
> 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
> 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:
> On Sat, Sep 22, 2012 at 6:17 PM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > 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:
> > --
> > 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