The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mongol - MongoDB ODM for Moose objects

SYNOPSIS

package Models::Person {
	use Moose;

	extends 'Mongol::Model';

	with 'Mongol::Roles::Core';
	with 'Mongol::Roles::Pagination';

	has 'first_name' => (
		is => 'ro',
		isa => 'Str',
		required => 1,
	);

	has 'last_name' => (
		is => 'ro',
		isa => 'Str',
		required => 1,
	);

	__PACKAGE__->meta()->make_immutable();
}

package main {
	...

	use MongoDB;

	use Mongol;

	my $mongo = MongoDB->connect(...);

	Mongol->map_entities( $mongo,
		'Models::Person' => 'test.people',
		...
	);

	...
}

DESCRIPTION

METHODS

map_entities

Mongol->map_entities( $mongo_connection,
	'My::Model::Class' => 'db.collection',
	'My::Model::Other' => 'db.other_collection',
);

Using a given MongoDB connection will automatically map a model class to a collection. After each initialization if exists the setup method on the model will be called.

AUTHOR

Tudor Marghidanu <tudor@marghidanu.com>

SEE ALSO

LICENSE

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.