I am trying to use a custom index in a MongoLab Collection, but I can't figure out how to get a Restangular.one response using this custom index. In truth, I can't even figure out how to send the call to MongoLab using just a URL with a custom index.
So, for instance, my collection has added the custom index "sitename". I tried this:
.when('/sites/:sitename', {
templateUrl: 'views/site.html',
controller: 'SiteCtrl',
resolve: {
site: function(Restangular, $route){
return Restangular.one('sites', $route.current.params.sitename).get();
}
}
})
but that didn't work. (I wasn't surprised). I also tried adding 'sitename' to the setRestangularFields section:
RestangularProvider.setRestangularFields({
id: '_id.$oid'
});
That also didn't help.
thanks for any help,
Scott
I figured this out with the help of Martin (maker of Restangular) and MongoLab support. Turns out I needed to do a customGet with Restangular and use the q: parameter to satisfy MongoLab. The final piece of code is a change on one line:
return Restangular.all('sites').customGET("", {q: { "sitename" : $route.current.params.sitename } });
so, the whole section would look like this:
.when('/sites/:sitename', {
templateUrl: 'views/site.html',
controller: 'SiteCtrl',
resolve: {
site: function(Restangular, $route){
return Restangular.all('sites').customGET("", {q: { "sitename" : $route.current.params.sitename } });
}
}
})
Hope this helps you.
Scott