Angular-meteor find MongoDb collection and return based on parameters

I am trying to get warnings for a specific address in my MongoDb using a combination of Meteor and Angular.js

In my html file I do

<div ng-controller = "myController as myCtrl"> {{myCtrl.warnings}} {{myCtrl.getWarnings("123 Test Street, TestCity, TestState")}} </div> 

in the app.js file:

 Warnings = new Mongo.Collection("Warnings"); if (Meteor.isClient) { var app = angular.module('ffprototype', [ 'angular-meteor' ]); app.controller('myController', ['$window','$meteor', function($window, $meteor) { this.warnings = $meteor.collection(Warnings); this.getWarnings = function(findByAddress){ Warnings.find({address: findByAddress}).fetch(); } }]); } 

My mongoDb collection:

 { "_id": "3ixgxEMZDWGtugxA7", "address": "123 Test Street, TestCity, TestState", "warning": "Warning 1" } { "_id": "HZH5FvCD5driBYSJz", "address": "123 Test Street, TestCity, TestState", "warning": "Warning 2" } 

The html web page displays the entire Warnings collection (thanks {{currentDispatch.warnings}} , but nothing is displayed for {{currentDispatch.getWarnings("123 Test Street, TestCity, TestState")}}

+7
angularjs mongodb meteor angular-meteor
source share
2 answers

You must use $ meteor.object for this

 this.getWarnings = function(findByAddress){ $meteor.object(Warnings, { address: findByAddress }, false); // passing false here to not update the collection from changes in the client } 
+6
source share

From angular -meteor docs , it looks like $meteor.object will be deprecated soon.

There is no need for $meteor.object , since we can use the Mongo Collections findOne , for example.

Old code:

 $scope.party = $meteor.object(Parties, $stateParams.partyId); 

New code:

 $scope.helpers({ party() { return Parties.findOne($stateParams.partyId); } }); 

More link one tutorial .

0
source share

All Articles