Backbone.js sents POST instead of PUT (mongoose set _id to id) Backbone.js sents POST instead of PUT (mongoose set _id to id) mongoose mongoose

Backbone.js sents POST instead of PUT (mongoose set _id to id)


From the fine manual http://backbonejs.org/#Model-idAttribute

idAttribute model.idAttribute

A model's unique identifier is stored under the id attribute. If you're directly communicating with a backend (CouchDB, MongoDB) that uses a different unique key, you may set a Model's idAttribute to transparently map from that key to id.


Id attribute can be changed per model like

var Meal = Backbone.Model.extend({  idAttribute: "_id"});

To make it default for all models (eg., if we are using mongodb), override the default setting by placing this LOC in your app js file that runs after backbone.js

//override the id attribute for modelBackbone.Model.prototype.idAttribute = '_id';