Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:16:37+00:00 2026-06-11T15:16:37+00:00

I have been playing with mongodb for a while. I dont get the concept

  • 0

I have been playing with mongodb for a while. I dont get the concept that when I try to remove a non-existing value or key it does not gives me an error.

        $host = '10.311.33.2';
        $user = 'admin'; $password = 'admin';
        tmpHost ="mongodb://$user:$password@$host";
        $m = new Mongo("$tmpHost");
        $db = $m->selectDB("common");
        $collection = new MongoCollection($db,"list");
        $result = array('name'=>'ali');
        $collection->insert($result);
        if($collection->remove($result)){
        echo "Remove";}
        else{
         echo "Not removed";}
        // Should display Not removed, since its not existing. but it displays Remove :S
        if($collection->remove($result)){
        echo "Remove";}
        else{
         echo "Not removed";}

How can such db be used,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:16:39+00:00Added an answer on June 11, 2026 at 3:16 pm

    You are calling MongoCollection::remove without the safe flag in the options (you are calling it without any options). That means the command behaves in a fire-and-forget manner. It is sent to the database and program execution continues without waiting for a reply.

    When you call it like that:

    $collection->remove($result, array("safe" => true))
    

    the return value will be an array which contains information about how the query worked. The field “n” of this array contains the number of affected objects. When the remove command did nothing, this should be 0.

    By the way: Most databases I worked with before do not treat a deletion query which doesn’t affect anything as an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing about with iText to try get a list of embedded
I have been playing around with creation of pdf documents for a project that
I have been playing with generics and was hoping I could get some feedback
I have been playing with image flood fill that I found here on Stack
I have been playing around with this and wanted to get a second opinion.
I have been playing around with jqgrid, and have the following question. To get
I have been playing with this for a while, but the closest I have
I have been playing around with a search control and i have noticed that
I have been playing with PHP & mySQL for a while now, as I
I have been playing around with GTK since a couple of days now,while going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.