use the following code, delete the specified document.
sub delete_post{
my $post_id = shift;
my $post_to_delete = $posts->find_one({"_id" => $conn->oid($post_id)})->{开发者_C百科_id};
$posts->remove({"_id" => $post_to_delete});
}
if use this code:
sub delete_post{
my $post_id = shift;
$posts->remove({"_id" => $conn->oid($post_id)});
}
remove all documents.
Does mongodb cannot accept the oid as criteria to delete document?
Use the MongoDB::OID method to create _id object instead of $conn->oid;
sub delete_post{
my $post_id = shift;
my $oid = MongoDB::OID->new(value => $post_id);
$posts->remove({"_id" => $oid});
$db->log->insert({"removed_post" => $post_id});
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论