从mongodb获取列表

时间:2015-12-07 12:10:02

标签: javascript mongodb rest

我是javascript的新手。我想从mongodb获取对象列表并在表中显示它们。 这是我的代码:

OrderResource

@Path("order/{size}")
@GET
public Object showOrder(@PathParam("size") String size){
    List<DBObject> OrderList = null;
    DBCollection collection = datastore.getDB().getCollection("Order");
    DBCursor OrderCursor = collection.find(QueryBuilder.start("size").is(size).get());
    OrderList = OrderCursor.toArray();

    if (OrderCursor == null) {
        throw new WebApplicationException(404);
    }

    GenericEntity<List<DBObject>> entity = new GenericEntity<List<DBObject>>(OrderList) {};
    return Response.ok(entity).build();
}

order.js

coffeeApp.factory('OrderFinder', function ($resource) {
return $resource('/service/coffeeshop/order/:size',
    {size: '@size'}, {}
)});
coffeeApp.controller('FindOrderController', function ($scope, $window, OrderFinder) {
$scope.findOrderBySize = function () {
        OrderFinder.query({size: "medium"}).$promise
            .then(
            function (response) {
                $scope.orders = response.orderBySize;

            });
};
$scope.findOrderBySize();});

order.html

<div ng-controller="FindOrderController" class="container">
<table>
    <tr>

        <th>Drinker</th>
    </tr>
    <tr ng-repeat="OrderBySize in orders">
        <th>{{OrderBySize.drinker}}</th>
    </tr>
</table>

但我的桌子还是空的。有什么问题?

0 个答案:

没有答案