xamenrax
xamenrax

Reputation: 1744

ember.js and mongoDB find object by id

Cheers! I get Foo (for example) object from remote server with an ID, which looks like this:

id: "5110e8b5a8fefe71e0000197"

But when I do:

App.Foo.find("5110e8b5a8fefe71e0000197")

it returns array of objects, which is wrong, 'cause all ID's are uniq in mongo.

> Array[112]

So, how to make it work?

UPDATE: My find function:

App.Foo.reopenClass({
  allFoos: [],
  find: function(){
    $.ajax({
      url: 'http://address/foos.json',
      dataType: 'jsonp',
      context: this,
      success: function(data){
        data.forEach(function(foo){
          this.allFoos.addObject(App.Foo.create(foo))
        }, this)
      }
    })
    return this.allFoos;
  }
});

Upvotes: 1

Views: 442

Answers (1)

sohel khalifa
sohel khalifa

Reputation: 5588

Try using this:

App.Foo.findOne({_id: "5110e8b5a8fefe71e0000197"})

Upvotes: 1

Related Questions