FeathersJS生成器有错误吗?

问题描述 投票:0回答:1

[使用feathersjs生成服务时,模型文件如下所示

import { Application } from '../declarations';

export default function (app: Application) {
  const modelName = 'comments';
  const mongooseClient = app.get('mongooseClient');
  const { Schema } = mongooseClient;
  const schema = new Schema({
    text: { type: String, required: true }
  }, {
    timestamps: true
  });

  // This is necessary to avoid model compilation errors in watch mode
  // see https://mongoosejs.com/docs/api/connection.html#connection_Connection-deleteModel
  if (mongooseClient.modelNames().includes(modelName)) {
    mongooseClient.deleteModel(modelName);
  }
  return mongooseClient.model(modelName, schema);
}

mongooseClient的类型为Mongoose,文档说deleteModel在Connection.prototype.deleteModel()

该行不应该说mongooseClient.connection.deleteModel(modelName);吗?

typescript mongoose feathersjs
1个回答
0
投票

不,不应该

[如果您查看根文件夹下的文件mongoose.js,您会看到'mongooseClient'mongoose.connect之后设置:

const mongoose = require('mongoose');

module.exports = function (app) {
  mongoose.connect(
    app.get('mongodb'),
    { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true }
  );
  mongoose.Promise = global.Promise;

  app.set('mongooseClient', mongoose);
};

因此它是Connection.prototype的一部分。

© www.soinside.com 2019 - 2024. All rights reserved.