【发布时间】:2014-04-13 13:31:12
【问题描述】:
假设我有一个如下所示的 mongodb items 集合(MongoLab):
{
"_id": {
"$oid": "531d8dd2e4b0373ae7e8f505"
},
"tags": [
"node",
"json"
],
"anotherField": "datahere"
}
{
"_id": {
"$oid": "531d8dd2e4b0373ae7e8f505"
},
"tags": [
"ajax",
"json"
],
"anotherField": "datahere"
}
我想获取node 在tags 数组中的所有项目。
我尝试了以下方法,但没有成功 - 它正在返回所有项目 - 没有执行搜索?
Plunker 演示: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 });
完整示例,两种情况都返回相同的记录:
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);
});
任何建议将不胜感激。
【问题讨论】:
-
您提供了与您的问题无关的代码...那里似乎很好的 Restangular 用法...它应该与您的服务器端有关...您能提供您的后端代码吗?
-
@wickY26 - 我使用 MongoLab 作为后端。所以问题一定出在我的
restangular search query。
标签: json angularjs mongodb restangular mlab