0.0.6 • Published 3 years ago
rugo-mongodb v0.0.6
Rugo MongoDB
Usage
const model = Model(db, modelName, modelSchema);
await model.create({
// obj
});
await model.get(id);
await model.find(query);
await model.patch(id, {
// obj key and value to update
});
await model.remove(id);
Schema
{
"<fieldName>": {
"type": "<typeName>",
"<optionName>": <optionValue>
}
}
Common configuration
All types accept a common set of configuration options.
Options:
- Only top level of schema:
index
: Iftrue
a database level index will be applied to this field, which can make searching faster.unique
: Iftrue
then all values of this field must be unique.default
: Define the default value when this field be set tonull
.
- All position:
required
: Iftrue
then this field can never be set tonull
.
Scalar types
checkbox
A checkbox
field represents a boolean (true
/false
) value.
datetime
A datetime
field represents a time value.
A email
field represents a email value. Inherit text
type.
number
A number
field represents a number value.
Options:
min
: The min value of this field.max
: The max value of this field.
password
A number
field represents an encrypted password value. The input value will be hashed to the next operation.
text
A text
field represents a string value.
Options:
minLength
: The min number of text characters.maxLength
:The max number of text characters.regex
: The regular expression to validate input data.trim
: Iftrue
, the string is trimed.lowercase
: Iftrue
, the string is transformed to lowercase.uppercase
: Iftrue
, the string is transformed to uppercase.
Complex types
document
A document
field represents a object (not array) value.
Options:
schema
: A schema for document value.
Example:
{
"type": "document",
"schema": {
"abc": {
"type": "text"
},
"xyz": {
"type": "number",
"default": 10
}
}
}
list
A list
field represents a array value.
Options:
children
: Aschema
for each item in list.
Example:
{
"pets": {
"type": "list",
"children": {
"type": "text",
"lowercase": true
}
}
}