Question

Lets assume I have an mongodb items collection looking like this (MongoLab):

{
    "_id": {
        "$oid": "531d8dd2e4b0373ae7e8f505"
    },
     "tags": [
        "node",
        "json"
    ],
    "anotherField": "datahere"
}
{
    "_id": {
        "$oid": "531d8dd2e4b0373ae7e8f505"
    },
     "tags": [
        "ajax",
        "json"
    ],
    "anotherField": "datahere"
  }

I would like to get all items where a node is within the tags array. I've tried the below, but no success - it is returning all items - no search performed?

Plunker demo : http://plnkr.co/edit/BYj09TOGyCTFKhhBXpIO?p=preview

// $route.current.params.id = "node" - should give me only 1 record with this tag
Restangular.all("items").customGET("", { "tags": $route.current.params.id });

Full example, return same record for both cases:

    var all = db.all('items');

    // GET ALL
    all.getList().then(function(data) {
        $scope.all = data;
        console.log(data);
    });

    // SEARCH for record where "tags" has got "node"
    all.customGET('', { "tags": "node"}).then(function(data) {
        $scope.search = data;
        console.log(data);
    });

Any suggestion would be much appreciated.

Was it helpful?

Solution

According to Mongolab REST API Documentation you have to pass the query object with the q parameter. In your case it is q={"tags":"node"}.

Using Restangular it will be like this:

Restangular.all("items").customGET('', { q: {"tags": "node"}})

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top