Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ejbp opened this issue Sep 20, 2016 · 1 comment
Open

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

ejbp opened this issue Sep 20, 2016 · 1 comment

Comments

@ejbp
Copy link

ejbp commented Sep 20, 2016

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
Copy link
Author

ejbp commented Sep 20, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant