> > self.db.fs.files.remove({"_id":ObjectId('{0}'.format(idd))})
> You need to use the GridFS API for this. All you are doing is removing
> the file metadata, not the chunks of binary data. The picture is not
> actually being removed.
> http://api.mongodb.org/python/current/api/gridfs/index.html#gridfs.Gr...
> On Mon, Sep 24, 2012 at 7:13 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > i got a bug in my application; if i upload TWO products, it's okey
> > when i delete one of them, but if i upload THREE i got an error from
> > GridFS telling me that the removed ID dont exists (and this is what i
> > wanted???)
> > here is the code:
> > class VentesHandler(BaseHandler):
> > @tornado.web.authenticated
> > def get(self):
> > user = self.get_secure_cookie("mechtari")
> > info = tornado.escape.json_decode(user)
> > email = info["personnel"]["email"]
> > try:
> > produits = self.db.users.find({"personnel.email":email},
> > {"produit_up":1,"_id":0}).distinct("produit_up")
> > renderer = self.fs
> > except (errors.AutoReconnect, errors.ConnectionFailure):
> > self.redirect("/error")
> > try:
> > self.render("ventes.html", produits=produits,
> > renderer=renderer)
> > except gridfs.errors.NoFile, e:
> > self.write(str(e))
> > class Supprimer(BaseHandler):
> > @tornado.web.authenticated
> > def post(self):
> > debut = time.clock()
> > prod = self.get_arguments("supprime")
> > produ = prod[0][:]
> > idd = self.db.users.find_one({"produit_up.spec.id":produ})
> > ["produit_up"][0["avatar"]["photo"]
> > try:
> > self.db.users.update({"produit_up.spec.id":produ},
> > {"$pull":{"produit_up"{"spec.id":produ}}})
> > self.db.fs.files.remove({"_id":ObjectId('{0}'.format(idd))})
> > except (errors.AutoReconnect, errors.ConnectionFailure):
> > self.redirect("/error")
> > self.redirect("/ventes") # this will redirect to the first code.
> > and the template:
> > {% for produit in produits %}
> > <div class="produit">
> > <span class="nom">Le nom du produit: {{produit["spec"]["namep"]}}</
> > span>
> > {% from bson import ObjectId %}
> > {% if produit["avatar"]["orientation"]=="portrait" %}
> > <span><img src="/{{renderer.get(ObjectId(produit["avatar"]
> > ["photo"])).filename}}"height="250px" class="imag">
> > {% else %}
> > <span><img src="/{{renderer.get(ObjectId(produit["avatar"]
> > ["photo"])).filename}}"width="250px"class="imag">
> > {% end %}
> > <div class="supprimer" >
> > <form name="supprimer" class="supprimer" method="post" action="/
> > supprimer">
> > {% raw xsrf_form_html() %}
> > <input type="hidden" value="{{produit["spec"]["id"]}}" name="supprime"/
> > <input type="submit" value="SUPPRIMER!"/>
> > </form>
> > </div>
> > as you can see, this two lines:
> > self.db.users.update({"produit_up.spec.id":produ}, {"$pull":
> > {"produit_up{"spec.id":produ}}})
> > self.db.fs.files.remove({"_id":ObjectId('{0}'.format(idd))})
> > the first one deletes the object, the second one clean its picture
> > from GridFS, but if there is more than one, it will make an error, for
> > example if i delete the object with
> > ObjectId('5060384f3a5f3a09488f7384') then i get an error when i'll be
> > redirected:
> > no file in gridfs collection
> > Collection(Database(Connection('localhost', 27017), u'essog'),
> > u'fs.files') with _id ObjectId('5060384f3a5f3a09488f7384')
> > and here is the link to stackoverflow (formatted):
> >http://stackoverflow.com/questions/12563503/how-to-delete-an-element-...
> > --
> > 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