I'm building an app using AngularJS and the MEAN Stack, and was wondering if it was possible to use the $resource factory to query a MongoDB database for a set of rows that have a certain value in one of their columns.
For example, if I wanted to build a Todo app, and I had a table with a column containing a persons username and a column with a string that had a reminder, is it possible to query the database for all the rows that have a particular username in the username column? Or, do I have to do something like this:
Todo.service.ts:
export function TodoResource($resource) {
'ngInject';
return $resource('/api/todo/:query', {
id: '@_id'
query: '';
});
}
app.js
var list = [];
this.Todo.query().$promise.then( (data) => {
for(let datum of data){
if(datum.userName == email){
list.push(datum);
}
}
});
In this sample case, I'm not really querying the database, just getting the entire table and filtering the results by myself. Is this the only way to do it, or can I directly query the database?
Aucun commentaire:
Enregistrer un commentaire