0

Say that my Schema is:

var fooSchema = new Schema({
  foo: String
});

and I want to add select: false to foo. How would I do that? Without doing the following:

var fooSchema = new Schema({
  foo: { type: String, select: false }
});

Can I do fooSchema.<somethingToAddSelectFalseToFoo>?

Adam Zerner
  • 17,797
  • 15
  • 90
  • 156

1 Answers1

0

I assume that this would work: Mongoose schema.set() function: http://mongoosejs.com/docs/api.html#schema_Schema-set.

Schema#set(key, [value])

Sets/gets a schema option.

Parameters:

key <String> option name
[value] <Object> if not passed, the current option value is returned

fooSchema.set('foo', { select: false });

In a select query you could exclude it, i.e. fooSchema.find().select("-foo"). Some examples are at https://stackoverflow.com/a/12097874/442472.

Community
  • 1
  • 1
Shan Plourde
  • 8,528
  • 2
  • 29
  • 42