Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:54:52+00:00 2026-06-17T12:54:52+00:00

I am working with mongoLab and the model id looks like this _id: {

  • 0

I am working with mongoLab and the model id looks like this

"_id": {
  "$oid": "50f9a0f5e4b007f27f766cf3"
},

I am using the idAttribute to set the model id to _id and everything works fine until I attempt to update the model.

Because the _id attribute exists in the model, I am getting an error when I attempt to insert.

Do I need to remove the attribute _id from my attributes? I was under the assumption that the magic of Backbone would clean up the attributes appropriately

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:54:54+00:00Added an answer on June 17, 2026 at 12:54 pm

    You would need to remove the _id attribute.

    In the MongoLab REST API, the id isn’t part of the data payload itself, but that isn’t the case for all backends. It probably makes more sense for Backbone to assume that the id should be present in the payload, than it would to assume it should not.

    That being said there’s no real nice way to get Backbone to clean the id from the payload automatically. Your best bet without monkeypatching/rewriting too much of the code would probably be to override Model#toJSON, something akin to:

    Backbone.Model.prototype.toJSON = function (options) {
      var attrs = _.clone(this.attributes);
      // In this case you'd have to pass `includeId: true` to `toJSON` when you
      // actually *want* the _id in the output.
      return options && options.includeId ? attrs : _.omit(attrs, '_id');
    };
    

    You could also monkeypatch sync, something like:

    var sync = Backbone.sync;
    Backbone.sync = function (method, model, options) {
      options || (options = {});
      // if options.attrs is present, Backbone will use it over dumping toJSON
      if (!options.attrs) options.attrs = _.omit(model.attributes, '_id');
      return sync.call(Backbone, method, model, options);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in Backbone.js, I'd like to set a model property from within a method
working on my code to retrieve lat,long by clicking and it works fine. wondering
Working on some small map of Europe with Raphael.js. It works fine in IE7+,
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number
Working with H2 I get this error when I try to write a row
Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how
Working with cakePHP this is my situation: I have Users and Order s. Order
Working through more book examples- this one is a partial poker program- This segment
Working on this question, I found an inconsistent behavior. Why reference binding behave different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.