首页 > 解决方案 > FeatherJs (express) 可扩展性问题

问题描述

我正在制作一个汽车市场,在解决字段时遇到了可扩展性问题。

我正在使用 MongoDb 和 FeatherJs(基于 Express)。我有以下 MongoDb 文档:listings、vehicles、vehicle_extras、users、users_profile、locations

在列表的正文中,我正在存储

  featuredUntil: { type: Date, default: null },
  locationId: {
    type: mongooseClient.Schema.Types.ObjectId,
    ref: "locations",
    required: true,
  },
  userId: {
    type: mongooseClient.Schema.Types.ObjectId,
    ref: "users",
    required: true,
  },
  vehicleId: {
    type: mongooseClient.Schema.Types.ObjectId,
    ref: "vehicles",
    required: true,
  },
 ... and more
},

现在在我的 Feather 列表挂钩(https://docs.feathersjs.com/api/hooks.html)中,我正在做一个

after: {
all: [
  fastJoin(vehicleResolver),
  fastJoin(userResolver),
  fastJoin(locationResolver),
],

有一个看起来像的解析器

const vehicleResolver = {
  joins: {
    vehicle: () => async (instance, context) => {
      try {
        if (instance && instance.vehicleId) {
          instance.vehicle = await context.app
            .service("vehicles")
            .get(instance.vehicleId);
        }
        return context;
      } catch (e) {
        return context;
      }
    },
  },
};

现在这一切都很有趣和游戏,但我的车辆正在额外解析车辆、图像等,并且请求 $limit=50 列表需要将近 7 秒。($limit=10 大约需要 1 秒)

如何使用 MongoDb 正确处理这个问题?我应该将所有(或更多数据)存储在单个文档中吗?

标签: node.jsmongodbexpressfeathersjs

解决方案


推荐阅读