sql >> Base de Datos >  >> NoSQL >> MongoDB

Manejo de relaciones en meteorito-angular

Terminé usando pasar tanto la colección como el filtrado usando angular:

Controlador

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

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

Publicación de meteoritos

Meteor.publish('branchesAndRestaurants', function(opts) {

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

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

Ver

<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>