.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Catmandu::Store::MongoDB 3pm" .TH Catmandu::Store::MongoDB 3pm "2021-09-02" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catmandu::Store::MongoDB \- A searchable store backed by MongoDB .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& # On the command line \& $ catmandu import \-v JSON \-\-multiline 1 to MongoDB \-\-database_name bibliography \-\-bag books < books.json \& $ catmandu export MongoDB \-\-database_name bibliography \-\-bag books to YAML \& $ catmandu count MongoDB \-\-database_name bibliography \-\-bag books \-\-query \*(Aq{"PublicationYear": "1937"}\*(Aq \& $ catmandu count MongoDB \-\-database_name bibliography \-\-bag books \-\-query \*(Aq{"Author": "Jones"}\*(Aq \-\-sort \*(Aq{"PublicationYear":1}\*(Aq \& \& # In perl \& use Catmandu::Store::MongoDB; \& \& my $store = Catmandu::Store::MongoDB\->new(database_name => \*(Aqtest\*(Aq); \& \& my $obj1 = $store\->bag\->add({ name => \*(AqPatrick\*(Aq }); \& \& printf "obj1 stored as %s\en" , $obj1\->{_id}; \& \& # Force an id in the store \& my $obj2 = $store\->bag\->add({ _id => \*(Aqtest123\*(Aq , name => \*(AqNicolas\*(Aq }); \& \& my $obj3 = $store\->bag\->get(\*(Aqtest123\*(Aq); \& \& $store\->bag\->delete(\*(Aqtest123\*(Aq); \& \& $store\->bag\->delete_all; \& \& # All bags are iterators \& $store\->bag\->each(sub { ... }); \& $store\->bag\->take(10)\->each(sub { ... }); \& \& # Search \& my $hits = $store\->bag\->search(query => \*(Aq{"name":"Patrick"}\*(Aq); \& my $hits = $store\->bag\->search(query => \*(Aq{"name":"Patrick"}\*(Aq , sort => { age => \-1} ); \& my $hits = $store\->bag\->search(query => {name => "Patrick"} , start => 0 , limit => 100); \& my $hits = $store\->bag\->search(query => {name => "Patrick"} , fields => {_id => 0, name => 1}); \& \& my $next_page = $hits\->next_page; \& my $hits = $store\->bag\->search(query => \*(Aq{"name":"Patrick"}\*(Aq , page => $next_page); \& \& my $iterator = $store\->bag\->searcher(query => {name => "Patrick"}); \& my $iterator = $store\->bag\->searcher(query => {name => "Patrick"}, fields => {_id => 0, name => 1}); \& \& # Catmandu::Store::MongoDB supports CQL... \& my $hits = $store\->bag\->search(cql_query => \*(Aqname any "Patrick"\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" A Catmandu::Store::MongoDB is a Perl package that can store data into MongoDB databases. The database as a whole is called a 'store'. Databases also have compartments (e.g. tables) called Catmandu::Bag\-s. .SH "CONFIGURATION" .IX Header "CONFIGURATION" .IP "database_name" 4 .IX Item "database_name" MongoDB database name. .IP "estimate_count" 4 .IX Item "estimate_count" Use a faster estimated collection document count if true. .PP All other options are passed on to the MongoDB client. .SH "METHODS" .IX Header "METHODS" .ie n .SS "new(database_name => $name, %connection_opts)" .el .SS "new(database_name => \f(CW$name\fP, \f(CW%connection_opts\fP)" .IX Subsection "new(database_name => $name, %connection_opts)" .ie n .SS "new(database_name => $name , bags => { data => { cql_mapping => $cql_mapping } })" .el .SS "new(database_name => \f(CW$name\fP , bags => { data => { cql_mapping => \f(CW$cql_mapping\fP } })" .IX Subsection "new(database_name => $name , bags => { data => { cql_mapping => $cql_mapping } })" Create a new Catmandu::Store::MongoDB store with name \f(CW$name\fR. Optionally provide connection parameters (see MongoDB::MongoClient for possible options). .PP The store supports \s-1CQL\s0 searches when a cql_mapping is provided. This hash contains a translation of \s-1CQL\s0 fields into MongoDB searchable fields. .PP .Vb 10 \& # Example mapping \& $cql_mapping = { \& indexes => { \& title => { \& op => { \& \*(Aqany\*(Aq => 1 , \& \*(Aqall\*(Aq => 1 , \& \*(Aq=\*(Aq => 1 , \& \*(Aq<>\*(Aq => 1 , \& \*(Aqexact\*(Aq => {field => [qw(mytitle.exact myalttitle.exact)]} \& } , \& sort => 1, \& field => \*(Aqmytitle\*(Aq, \& cb => [\*(AqBiblio::Search\*(Aq, \*(Aqnormalize_title\*(Aq] \& } \& } \& } .Ve .PP The \s-1CQL\s0 mapping above will support for the 'title' field the \s-1CQL\s0 operators: any, all, =, <> and exact. .PP The 'title' field will be mapped into the MongoDB field 'mytitle', except for the 'exact' operator. In case of 'exact' both the \&'mytitle.exact' and 'myalttitle.exact' fields will be searched. .PP The \s-1CQL\s0 mapping allows for sorting on the 'title' field. If, for instance, we would like to use a special MongoDB field for sorting we could have written \&\*(L"sort => { field => 'mytitle.sort' }\*(R". .PP The \s-1CQL\s0 has an optional callback field 'cb' which contains a reference to subroutines to rewrite or augment the search query. In this case, in the Biblio::Search package contains a normalize_title subroutine which returns a string or an \s-1ARRAY\s0 of string with augmented title(s). E.g. .PP .Vb 1 \& package Biblio::Search; \& \& sub normalize_title { \& my ($self,$title) = @_; \& # delete all bad characters \& my $new_title =~ s{[^A\-Z0\-9]+}{}g; \& $new_title; \& } \& \& 1; .Ve .SS "bag($name)" .IX Subsection "bag($name)" Create or retieve a bag with name \f(CW$name\fR. Returns a Catmandu::Bag. .SS "client" .IX Subsection "client" Return the MongoDB::MongoClient instance. .SS "database" .IX Subsection "database" Return a MongoDB::Database instance. .SS "drop" .IX Subsection "drop" Delete the store and all it's bags. .SS "transaction(\e&sub)" .IX Subsection "transaction(&sub)" Execute \f(CW$sub\fR within a transaction. See Catmandu::Transactional. .PP Note that only MongoDB databases with feature compatibility >= 4.0 and in a replica set have support for transactions. See and for more info. .SH "Search" .IX Header "Search" Search the database: see Catmandu::Searchable and Catmandu::CQLSearchable. This module supports an additional search parameter: .PP .Vb 1 \& \- fields => { => <0|1> } : limit fields to return from a query (see L) .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Catmandu::Bag, Catmandu::CQLSearchable, Catmandu::Droppable, Catmandu::Transactional, MongoDB::MongoClient .SH "AUTHOR" .IX Header "AUTHOR" Nicolas Steenlant, \f(CW\*(C`\*(C'\fR .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Johann Rolschewski, \f(CW\*(C`\*(C'\fR .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" This program is free software; you can redistribute it and/or modify it under the terms of either: the \s-1GNU\s0 General Public License as published by the Free Software Foundation; or the Artistic License. .PP See http://dev.perl.org/licenses/ for more information.