A lightweight ODM for MongoDB, made by MikeFMeyer & FWMoor.
Add the following to the schema to validate the input:
-
required
If required is set to true, input is expected. If not input is received, an error will be added to the object.Expects a boolean value.
-
min
Min sets the minimum value of the input received. If the input is less, an error will be added to the object.Expects a numeric value.
-
max
Max sets the maximum value of the input received. If the input is more, an error will be added to the object.Expects a numeric value.
-
length
Length sets the minimum length of the input. If the input's length is less, an error will be added to the object.Expects a numeric value.
-
max-length
Max-length sets the maximum length of the input. If the input's is more, an error will be added to the object.Expects a numeric value.
-
strong
If strong is set to true, the input is checked to see if it contains at least 1 lowercase character, 1 uppercase character, 1 numeric value and 1 special character. If it doesn't, an error will be added to the object.Expects a boolean value.
-
email
If email is set to true, the input is checked to see if it is a valid email address (only the formating of the address is checked). If not, and error is added to the object.Expects a boolean value.
-
matches
Matches compares the input to the given key's input. If they're not the same or the given key doesn't exist, an error is added to the object.Expects a key name.
-
hash
If hash is set to true, the input is hashed using bcrypt.Expects a boolean value.
-
default
This allows you to set a default value for a field. If no input value is given the default value will be used.Expects any value.
-
enum
Checks if input fits into a given enum. If not, an error is added to the object.Expects an array of possible values.
-
connect (url, database name, callback function):
Used to makes a connection to the database. -
getPrimaryKey (id):
- insertOne (data, callback function):
Used to insert document into a collection.
-
findAll (callback function):
Returns all the documents in a collection. -
findById (id, callback function):
Returns the documents in a collection with the same id as the one provided. -
findOneById (id, callback function):
Returns one document in a collection with the same id as the one provided. -
findByAny (options, callback function):
Returns the documents in a collection with the same value(s) as the value(s) provided. -
findOneByAny (options, callback function):
Returns one document in a collection with the same value(s) as the value(s) provided.
-
updateById (id, data, callback function):
Updates the value in the collection with the same id as the one provided. -
updateManyById (id, data, callback function):
Updates the values in the collection with the same id as the one provided.
-
deleteAll (options, callback function):
Deletes all the values from a collection where the options are the same as the ones provided. -
deleteOne (id, callback function):
Deletes one value from the collection where the id is the same as the one provided.
mongodb - Database.
bcrypt - For hashing passwords and input.
Mike Meyer | Frederick Moor |
See the license file for license rights and limitations (MIT).
Moose is a very lightweight ODM for MongoDB, please read the documentation before using it.