I have a collection and a model but hitting issues when trying to save with node.js and mongodb. If I don't set the id attribute in the code, it always does a post. It saves the data but put is never hit. So I decided to try an use the idattribute on the model but then hit the error "error: argument passed in most be a single string etc" now the value of the variable is 100004782669837. If this is too large, do I need to come up with a new kind of index?
This is my model. ActiveId is 100004782669837
bb.model.ActiveMember = Backbone.Model.extend({
idAttribute: "ActiveId",
defaults: {
ActiveName: 'Test',
Handicap: '18',
Par: '4',
Putts: '2',
ActiveId:'1'
},
Saved: function(parr,puttt,hand) {
var self = this
self.save({Par:parr, Putts:puttt,Handicap:hand})
}
})
I call this from my collection with the following code
var last_model = self.find(function(item){return item.get("ActiveId") === mem;});
last_model.Saved(parr,puttt,hand)
This is where it crashes in the node js line. Its on the mongodb line that the crash happens
util.fixid = function( doc ) {
console.log('in util fixid')
if( doc._id ) {
doc.id = doc._id.toString()
delete doc._id
}
else if( doc.id ) {
doc._id = new mongodb.ObjectID(doc.id)
delete doc.id
}
return doc
}
I'm not sure how I can get the id of the model, I have followed some examples but maybe I'm missing something