0

How do you go about finding all the [options] available to you when they are not listed out?

In the case of mongoose for nodejs: http://mongoosejs.com/docs/api.html#schema_Schema-index

Examples help but are not often complete. How does one track down the full extent of the options you can pass in as the second parameter?

It reads:

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 })

In some places, all the options are detailed out, which is wonderful. example:

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

Thanks.

Also, I found this lovely question/answer.

How to read API documentation for newbs?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
cathy.sasaki
  • 3,995
  • 6
  • 28
  • 39
  • One of the best way to find out what options (indeed any functionality) are available is to look at the tests. – booyaa May 13 '13 at 07:57
  • Smart suggestion. So, I just go to source code into the tests. Got it. – cathy.sasaki May 13 '13 at 11:29
  • This is assuming they write good tests though ;) in the case of this project you'll be fine: https://github.com/LearnBoost/mongoose/blob/master/test/schema.test.js#L1028 – booyaa May 13 '13 at 13:03
  • Nice. Thanks for pointing to the place. So, the options are (did I miss any?): unique: Boolean, sparse: Boolean, expireAfterSeconds: Number, type: (eg. String,Date,Number.._, expires: String (eg. '24h'), background: Boolean – cathy.sasaki May 13 '13 at 13:48
  • Yup that looks right, but be careful the index options are dependent on the Type: https://github.com/LearnBoost/mongoose/blob/master/lib/schematype.js#L96 – booyaa May 13 '13 at 15:06
  • Got it. They put more documentation into the doc string than in the api docs. :D Now I know to look at the doc string of the tests AND the tests. – cathy.sasaki May 13 '13 at 18:20
  • By the way, if you want to write that up in the answer, I'd accept because I think when the API docs are incomplete, the only way to understand more is to introspect the code, and the easiest first step is indeed look at the tests. – cathy.sasaki May 13 '13 at 18:21
  • Thanks I've posted our conversation as an answer :) – booyaa May 14 '13 at 14:29

1 Answers1

3

The obvious answer is to read through the source code, but frequently I've found it's often easier to read the tests. The tests will often be the bits of code that the developer(s) cares about.

In the case of Schema Index the tests alluded to several options: https://github.com/LearnBoost/mongoose/blob/master/test/schema.test.js#L1028

However after further digging a lot of the options were tied to a specific schema type: https://github.com/LearnBoost/mongoose/blob/master/lib/schematype.js#L96

booyaa
  • 4,437
  • 2
  • 26
  • 32