【问题标题】:Reading incomplete API docs - how do you know what all your [options] are if they are not listed?阅读不完整的 API 文档——如果没有列出,你怎么知道你的所有 [选项] 是什么?
【发布时间】:2023-03-15 08:42:02
【问题描述】:

[options] 未列出时,您如何找到所有可用的[options]

对于mongoosenodejshttp://mongoosejs.com/docs/api.html#schema_Schema-index

示例有帮助,但通常并不完整。如何跟踪可以作为第二个参数传入的 options 的全部范围?

上面写着

Schema#index(fields, [options])

Defines an index (most likely compound) for this schema.

show code
Parameters:

fields <Object>
[options] <Object>
Example

schema.index({ first: 1, last: -1 }, { unique: true })

在某些地方,所有选项都被详细列出,这很棒。 示例:

http://mongoosejs.com/docs/api.html#connection_Connection-openSet

谢谢。

另外,我发现了这个可爱的问题/答案。

How to read API documentation for newbs?

【问题讨论】:

  • 找出可用选项(实际上是任何功能)的最佳方法之一是查看测试。
  • 聪明的建议。所以,我只是去测试源代码。明白了。
  • 这是假设他们编写了很好的测试;)在这个项目的情况下你会没事的:github.com/LearnBoost/mongoose/blob/master/test/…
  • 不错。谢谢你指点这个地方。所以,选项是(我错过了吗?):唯一:布尔,稀疏:布尔,expireAfterSeconds:数字,类型:(例如字符串,日期,数字.._,过期:字符串(例如'24h '), 背景:布尔值
  • 是的,看起来不错,但要注意索引选项取决于类型:github.com/LearnBoost/mongoose/blob/master/lib/…

标签: node.js api mongoose


【解决方案1】:

显而易见的答案是通读源代码,但我经常发现阅读测试通常更容易。测试通常是开发人员关心的代码。

对于 Schema Index,测试提到了几个选项:https://github.com/LearnBoost/mongoose/blob/master/test/schema.test.js#L1028

但是在进一步挖掘之后,很多选项都与特定的模式类型相关联:https://github.com/LearnBoost/mongoose/blob/master/lib/schematype.js#L96

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2011-02-20
    • 2011-11-18
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    相关资源
    最近更新 更多