as from version 3.2 MongoDB supports natively document validation
https://docs.mongodb.com/manual/core/document-validation/
is this currently supported or is there a plan to add it?
+1
any update on this?
Also interested in knowing if this is implemented
+1
Why was this closed? I am looking for this feature as well but I can't see it in the docs.
Sorry if it is a dumb question, I am new to this package.
I think all you need is https://github.com/suren1986/laravel-mongo-model-schema read also
https://packagist.org/packages/suren/laravel-mongo-model-schema
Thank you very much @Modex987, I'll check it out
Init your own builder within the up() method of your migration file, and you're good to go:
use Jenssegers\Mongodb\Connection;
use Jenssegers\Mongodb\Schema\Builder;
public function up()
{
$connection = new Connection(
Config::get('database.connections.mongodb_test')
);
$builder = new Builder($connection);
$builder->create('users', function(Blueprint $collection){
$collection->unique('username');
$collection->unique('email');
}, [
'validator' => [
'$jsonSchema' => [
'bsonType' => 'object',
'required' => [
'username',
'email',
'password',
],
'additionalProperties' => false,
'properties' => [
'_id' => [
'bsonType' => 'objectId'
],
'username' => [
'bsonType' => 'string',
'minLength' => 8,
'maxLength' => 8
],
'email' => [
'bsonType' => 'string',
'maxLength' => 255
],
'password' => [
'bsonType' => 'string',
'maxLength' => 255
]
]
]
],
'validationLevel' => 'strict',
'validationAction' => 'error'
]);
}
Most helpful comment
Init your own builder within the up() method of your migration file, and you're good to go: