You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide.jade
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -250,7 +250,29 @@ block content
250
250
:markdown
251
251
Virtual property setters are applied before other validation. So the example above would still work even if the `first` and `last` name fields were required.
252
252
253
-
Only non-virtual properties work as part of queries and for field selection.
253
+
Only non-virtual properties work as part of queries and for field selection. Since virtuals are not stored in MongoDB, you can't query with them.
254
+
255
+
h5#aliases Aliases
256
+
:markdown
257
+
Aliases are a particular type of virtual where the getter and setter seamlessly get and set another property. This is handy for saving network bandwidth, so you can convert a short property name stored in the database into a longer name for code readability.
258
+
259
+
:js
260
+
var personSchema = new Schema({
261
+
n: {
262
+
type: String,
263
+
// Now accessing `name` will get you the value of `n`, and setting `n` will set the value of `name`
Copy file name to clipboardExpand all lines: docs/schematypes.jade
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -112,13 +112,15 @@ block content
112
112
* `validate: function, adds a [validator function](http://mongoosejs.com/docs/validation.html#built-in-validators) for this property
113
113
* `get`: function, defines a custom getter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
114
114
* `set`: function, defines a custom setter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
115
+
* `alias`: string, mongoose >= 4.10.0 only. Defines a [virtual](http://mongoosejs.com/docs/guide.html#virtuals) with the given name that gets/sets this path.
0 commit comments