【问题标题】:Why we add 's' after the name of collection when we want drop that? [duplicate]为什么要删除集合名称时要在集合名称后添加“ s”? [复制]
【发布时间】:2018-10-08 15:10:53
【问题描述】:

在这里我想删除我的集合(MySQL 中的表),但我不明白为什么我们在集合名称中添加“s”,示例:
[集合(表)的名称:myCollection]

const mongoose = require('mongoose');
 mongoose.connection.collections.myCollections.drop();

【问题讨论】:

  • 请在此处发布之前实际搜索答案。您的问题标题与现有答案几乎完全相同。我很容易找到,别人也很容易找到。这样的事情很容易找到,事实上,你从这些问题中获得的大多数答案都只是从容易找到的答案中复制而来。这就是我们要求您先搜索的原因,因为我们不希望这样。

标签: javascript node.js mongoose


【解决方案1】:

一个模型代表一个单一的项目。一个集合是一堆那些奇异的项目。 Mongoose 会自动进行复数,因此您必须深入研究文档以了解如何自定义或调整它。

根据他们的文档Mongoose by default produces a collection name by passing the model name to the utils.toCollectionName method. This method pluralizes the name. Set this option if you need a different name for your collection.

查看http://mongoosejs.com/docs/guide.html 了解更多信息

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2011-11-21
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    相关资源
    最近更新 更多