Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
DoesNotExist: [Model] matching query does not exist at id (ObjectId)

I am trying to query a unique document using its ObjectId. However the error comes up:

DoesNotExist: Route matching query does not exist

When, upon passing this to my view as request, it prints out the corresponding ObjectId in ObjectId typeform. Therefore there shouldn't be a problem with the line route_test = Route.objects.get(id=_id). I have the following code:

views.py

def update(request):

    if request.method == "POST":

        _id = request.POST.get('_id',ObjectId())
        print(_id)
        route_id = request.POST.get('route_id','')
        geometry = request.POST.get('geometry', '')
        properties = request.POST.get('properties','')

        #r = Route.objects.get(route_id='LTFRB_PUJ2616') --> I cannot use this
                                      #because it has 5 instances (Not Unique)
        #print (r["id"],r["properties"]) 

        test = Route.objects.get(id = ObjectId('587c4c3b203ada19e8e0ecf6'))
        print (test["id"], test["properties"])

        try:
            route_test = Route.objects.get(id=_id)
            print(route_test)
            Route.objects.get(id=_id).update(set__geometry=geometry, set__properties=properties)
            return HttpResponse("Success!")

        except:
            return HttpResponse("Error!")

ajax

 var finishBtn = L.easyButton({
     id:'finish',
     states: [{
              icon:"fa fa-check",
              onClick: function(btn){
                  selectedFeature.editing.disable();
                  layer.closePopup();
                  var editedFeature = selectedFeature.toGeoJSON();
                  alert("Updating:" + editedFeature.route_id);

                  $.ajax({
                     url: "/update/",
                     data: {id:editedFeature.id,
                            route_id: JSON.stringify(editedFeature.route_id),
                            geometry: JSON.stringify(editedFeature.geometry),
                            properties: JSON.stringify(editedFeature.properties)
                         }, 
                     type: 'POST'     
            });
 }

model.py

from __future__ import unicode_literals

from mongoengine import *

class Route(Document):
    type = StringField(required=True)
    route_id = StringField(required=True)
    geometry = LineStringField()
    properties = DictField()

    meta = {'collection':'routes'}

What should be done? Even the line test = Route.objects.get(id = ObjectId('587c4c3b203ada19e8e0ecf6')) where I directly supplied the incoming _id has the same error...

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda