in reply to Creating a perl delete statement with MongoDB

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

Replies are listed 'Best First'.
Re^2: Creating a perl delete statement with MongoDB
by e0s (Novice) on Jul 21, 2017 at 01:39 UTC
    thank you so much, that's actually really helpful.
A reply falls below the community's threshold of quality. You may see it by logging in.