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.
poj#!/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; }
In reply to Re: Creating a perl delete statement with MongoDB
by poj
in thread Creating a perl delete statement with MongoDB
by e0s
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |