summaryrefslogtreecommitdiff
path: root/node_modules/mongoose/docs/defaults.md
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/mongoose/docs/defaults.md
ok
Diffstat (limited to 'node_modules/mongoose/docs/defaults.md')
-rw-r--r--node_modules/mongoose/docs/defaults.md29
1 files changed, 29 insertions, 0 deletions
diff --git a/node_modules/mongoose/docs/defaults.md b/node_modules/mongoose/docs/defaults.md
new file mode 100644
index 0000000..0497787
--- /dev/null
+++ b/node_modules/mongoose/docs/defaults.md
@@ -0,0 +1,29 @@
+
+Defaults
+========
+
+Each `SchemaType` that you define \(you can read more about them in the [model
+definition chapter](/docs/model-definition.html) \) can have a default value.
+
+Default values are applied when the document skeleton is constructed. This
+means that if you create a new document (`new MyModel`) or if you find an
+existing document (`MyModel.findById`), both will have defaults
+provided that a certain key is missing.
+
+## Definition
+
+You can define a default with a function:
+
+ new Schema({
+ date: { type: Date, default: Date.now }
+ })
+
+or a value:
+
+ new Schema({
+ date: { type: Date, default: '12/10/1990' }
+ })
+
+Notice that defaults are automatically casted. In both cases, the defaults will
+become actual `Date` objects, but we're passing a timestamp first, and a string
+date second.