MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Manipulando relacionamentos em meteor-angular


Acabei usando passando a coleção e filtrando usando angular:

Controlador
angular.module("sushisushi24").controller("SearchRestaurantsCtrl",
    function($scope, $stateParams, $meteor){

        $scope.branches = $meteor.collection(Branches).subscribe('branchesAndRestaurants');
        $scope.restaurants = $meteor.collection(Restaurants);
    }
);

Publicação de meteoros
Meteor.publish('branchesAndRestaurants', function(opts) {

    branches = Branches.find();
    restaurantIds = branches.map(function(branch) { return branch.restaurantId });

    return [
        branches,
        Restaurants.find({_id: {$in: restaurantIds}})
    ];
});

Visão
<div ng-repeat="branch in branches">
    <div ng-repeat="restaurant in restaurants | filter: {_id:branch.restaurantId}">
        <h3>{{restaurant.name}}</h3>
    </div>
    <address>{{branch.address}}</address>
</div>