【发布时间】:2020-08-25 17:42:50
【问题描述】:
我有一个使用 Express+Typescript 的节点服务器,它使用 Mongoose 连接到 MongoDB 数据库。
在我的数据库中,我有一个名为 Products 的集合,前端(Angular 9)请求显示它们。
现在我只需发送一个GET 请求,我的服务器就会返回所有产品:
public async getAll() {
const products = await this.productModel.find({}).then(products => products).catch(() => false)
if (!products)
throw new Error('Could\'nt get products')
return products
}
角度:
getAllProducts() {
return this.http.get<IProduct[]>('http://127.0.0.1:3000/products/')
}
我的问题是如何按“块”检索产品,例如每个请求的 n 产品也无需重复产品?
【问题讨论】:
标签: javascript node.js angularjs mongodb mongoose