node-restful icon indicating copy to clipboard operation
node-restful copied to clipboard

Cannot delete a document when changing _ID in schema - Error on route

Open ejbp opened this issue 8 years ago • 1 comments

This is my mongoose Schema in my model file:

var ContentTagSchema = new mongoose.Schema({
    _id: { type : String, lowercase: true, required: true, index: true, unique: true},
    description: String
});
module.exports = restful.model('ContentTag', ContentTagSchema);

This is my register file for routes:

var ContentTag = require('../models/ContentTagSchema');
ContentTag.methods(['get', 'put', 'post', 'delete']);
ContentTag.register(router, '/api/v2/content/tags');
ContentTag.on('index', function(err) { 
    if (err) {
        console.error('ContentTag index error: %s', err);
    } else {
        console.info('ContentTag indexing complete');
    }
});

Result:

DELETE /api/v2/content/tags/jon 404 2.188 ms - 1795

Error: Not Found
    at /DIR/api/v2/xxx.js:53:13
    at Layer.handle [as handle_request] (/DIR/api/v2/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/DIR/      [......]

Here is db.collection.find({}) from db:

db.contenttags.find({}) { "_id" : "peter", "__v" : 0 } { "_id" : "language-english", "__v" : 0 } { "_id" : "jon", "__v" : 0 } { "_id" : "language", "__v" : 0 }

Any idea? Thanks.

ejbp avatar Sep 20 '16 11:09 ejbp

Ok. I've figure out. The "problem" or feature is in the model.js file in the registerRoutes function where you filter the _id route to ([0-9a-fA-F]{0,24}$). I removed the line and now it's working.

ejbp avatar Sep 20 '16 16:09 ejbp