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 8850891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:00:23+00:00 2026-06-14T13:00:23+00:00

I am fetching a mongodb collection from server using backbone collection. Since the ids

  • 0

I am fetching a mongodb collection from server using backbone collection. Since the ids are stored as ‘_id’, I used idAttribute to map it to ‘_id’.

(function(){
  var PlaceModel = Backbone.Model.extend({
    idAttribute: "_id",
  });
  var PlaceCollection = Backbone.Collection.extend({
    url: "http://localhost:9090/places",
    initialize: function(options){
      var that = this;
      this.fetch({
        success: function(){
          console.log("Success!", that.toJSON());
        },
        error: function(){
          console.log("Error");
        }
      });
    }
  });

  var place = new PlaceCollection({model:PlaceModel});

}()); 

But later on when I try to access the model’s ‘idAttribute’ when it’s time to DELETE an entry, it returns ‘id’ instead of ‘_id’, which means this.model.isNew() from the view returns ‘true’ for all the records fetched from the server. Therefore I cannot DELETE nor PUT an entry to the server.

However if I set the idAttribute using prototype like this (instead of inside the PlaceModel definition):

Backbone.Model.prototype.idAttribute = "_id";

Then it correctly maps the idAttribute to ‘_id’, and everything works. What might be happening?

  • 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-14T13:00:24+00:00Added an answer on June 14, 2026 at 1:00 pm

    When you say this:

    var place = new PlaceCollection({model:PlaceModel});
    

    That’s the same, more or less, as saying this:

    var o     = new Backbone.Model({ model: PlaceModel });
    var place = new PlaceCollection([ o ]);
    

    You’re not setting the collection “class”‘s model property, you’re just creating a collection with one model in it (a plain Backbone.Model instance, not a PlaceModel) and that model has a model attribute with value PlaceModel.

    So, given all that, the collection has no idea that its model is supposed to have idAttribute: "_id" or even that its model is supposed to be a PlaceModel. You want to see the model when you create PlaceCollection, not when you create place:

    var PlaceCollection = Backbone.Collection.extend({
      url: "http://localhost:9090/places",
      model: PlaceModel,
      //...
    });
    
    var place = new PlaceCollection;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While fetching quite a large Backbone collection from a REST service with IE8 I
I am fetching some data from a site using its API-key and some other
I am fetching some values in a forEach clause data.forEach(function(content){ ... controller.setAttribute(value from data);
I'm fetching some data from an MSSQL table using the mssql_fetch_object, but the text
When fetching content from a database using activerecord, I would like to fetch a
I am fetching data from cursor. Using this cursor i am populating the text
i am fetching data from a table using mysql_fetch_aaray the data is displaying correctly
im fetching an image from internet using the below code using an Async task,But
I am fetching a lot of thumbnails in my application from a remote server
I'm using mongodb, node.js and backbone.js to build an app that will serve as

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.