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

  • SEARCH
  • Home
  • 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 8908115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:05:48+00:00 2026-06-15T03:05:48+00:00

how do i use getLastError() within php to check if my save method is

  • 0

how do i use getLastError() within php to check if my save method is inserting to mongo?

i set up my db as follows:

$this->databaseEngine = $app['mongo'];
$this->db = $this->databaseEngine->dbname;
$this->collection = $this->db->collectionname;

my insert query then looks like this:

$query = array(
    'fieldname' => $fieldname
);
$this->collection->insert($query);

I want to then use getLastError() to check whether it is inserting correctly, and if not why. but im not sure how to implement it.

do i use after the insert:

$this->collection->getLastError("what goes here?");

cheers.

Update

i eventually used this to get the last error:

echo '<pre>' . print_r($this->databaseEngine->lastError(), true) . '</pre>';

Sammaye’s way works just as well, see below.

  • 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-15T03:05:49+00:00Added an answer on June 15, 2026 at 3:05 am

    $this->collection->getLastError(“what goes here?”);

    Nothing goes there, the return of the getLastError is the last error from MongoDB ( http://www.php.net/manual/en/mongodb.lasterror.php ). Also it is used on the MongoDB class (atm).

    You don’t have to use it like that, instead you can do:

    $this->collection->insert($query, ARRAY('safe' => TRUE));
    

    This will return an array from the function detailing whether or not it actually inserted. The details of the array can be found by reading this page:

    http://www.php.net/manual/en/mongocollection.insert.php

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

Sidebar

Related Questions

ANSWER: There isn't a natively managed equivalent for this method. However, a good example
I use the Application_Error event to catch and log errors in my app. The
I am confused over whether to use Server.GetLastError or HttpContext.Current.Server.GetLastError in the Application_Error event.
I use IMAPIProp::CopyTo in an add-in for Outlook 2010 to save the currently displayed
I'm trying to use devcon.exe to check the status of various pieces of hardware.
I use the CreateProcess() function to launch the rdp client app using mstsc.exe. After
I have this code that I need to use, but what holds me back
I'm trying to use CreateFileMapping and OpenFileMapping to share memory between processes. This isn't
I use TCP function recv to receive data. Then use GetLastError() to display the
I'm using various Win32 API functions in my Java application and I use GetLastError

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.