У меня есть две коллекции: одна с пользователями, а другая с предложениями о работе (ofertas).Несмотря на то, что я могу найти одного пользователя, я изо всех сил стараюсь сделать это для всех предложений в моей коллекции «ofertas».Это то, что у меня есть: ofertas.js на моем сервере: server / routs / ofertas.js
router.get('/ofertas', async(req, res) => {
try {
const oferta = await Oferta.find();
res.json(oferta);
} catch (e) {
console.log(e);
}
});
oferta.service.ts в моем клиенте: src/app/oferta.service.ts
ofertas() {
return this.http.get('http://127.0.0.1:3000/ofertas/oferta', {
observe: 'body',
withCredentials: true,
headers: new HttpHeaders().append('Content-Type', 'application/json')
});
}
}
И вот как я звоню из компонента: src / app / pages / ofertas.component.ts
constructor(private ofertas: OfertaService, private router: Router) {
this.ofertas.ofertas()
.subscribe(
data => this.results(data),
error => this.router.navigate(['/login'])
);
}
Так я извлекаю одного пользователя из моей коллекции «Пользователи», но я не знаю, как это сделать для массива.Это моя модель для Ofertas (это схема мангуста):
var schema = new Schema({
idUser: { type: String, require: true },
empresa: { type: String, require: true },
puesto: { type: String, require: true },
salario: { type: String, require: true }
});