Not sure why you want to separate a fruit NAME from it's ID by using 2 collections. Maybe this demo will help you explain.

#!/usr/bin/perl use strict; use MongoDB; # connect to database my $client = MongoDB->connect( 'mongodb://localhost:27017' ); my $db = $client->get_database( 'test' ); $db->drop; # start with empty database # insert some test data my @fruits = qw(apple banana cherry damson elderberry fig grape kiwi mango orange pear raspberry strawberry tangerine ugli watermelon); my $fruits = $db->get_collection('fruits'); my $id = 1; for (@fruits){ # put ID and NAME in same collection $fruits->insert_one({ uid => "$id", name => $_}); ++$id; } # show table and get user input my $entry; while ($entry ne 'q') { my $all_fruits = $fruits->find; while (my $doc = $all_fruits->next) { printf " %2s %s\n",$doc->{'uid'},$doc->{'name'}; } print "Enter ID or Name (q to quit) > "; chomp($entry = <STDIN>); # use OR for either ID or Name my $res = $fruits->delete_one( { '$or' => [ {uid=>$entry}, {name=>$entry} ] } ); printf "\n[$entry] %d records deleted \n",$res->deleted_count; }
poj

In reply to Re: Creating a perl delete statement with MongoDB by poj
in thread Creating a perl delete statement with MongoDB by e0s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.