LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-17-2016, 04:08 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
php mongo simple update not working


Hello all,

I have written a simple php update command in php to update a mongo collection, I have followed example guides and the documentation, however for some reason my code will not update the collection in question.

Additionally, there are no errors, so I am at a bit of a loss with this one:

Code:
    $find = array('_id' => new MongoId($_id));
    $update = array('$set' => array('admin' => 'false'));
    $db->user->update($find, $update);
Example collection
Code:
{
    "_id" : ObjectId("57ad95301816a3bd078b4567"),
    "admin" : "false",
    "created_dstamp" : "2016-08-12 19:21:52",
    "email" : "yo@yo.yo",
    "last_login" : null,
    "password" : "7f49e93c9cae6b0d40e3c2f1154fe6",
    "salt" : "804551d0fa708e93cf1163d",
}
 
Old 08-17-2016, 04:10 AM   #2
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
actually, I've just noticed that it has updated in the DB but not on the website, weird
 
Old 08-17-2016, 04:35 AM   #3
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
Ok, looks like I am still having issues with this, Im not sure what happened, but I still cannot set the admin value to false:

Code:
    $find = array('_id' => '57ad95301816a3bd078b4567');
    $update = array('$set' => array('admin' => 'hsjgahsgdas'));
    $db->user->update($find, $update);
If anyone could help that would be great, I have tried also using 'new MongoId('57ad95301816a3bd078b4567')' and 'Object('57ad95301816a3bd078b4567')', however it still wont update the collection
 
Old 08-17-2016, 05:00 AM   #4
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
This worked in the end:

Code:
    $f = array('_id' => new MongoId("{$_GET['id']}"));
    $db->user->update($f, array('$set' => array('admin' => false)));
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php file command not working after server update linux6 Linux - Newbie 1 04-10-2016 09:16 AM
PHP MySQL Support not working (Hopefully simple question) icarusfall Linux - Software 5 11-08-2005 10:30 AM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 08:02 PM
Simple PHP form not working... Booster Programming 4 02-23-2004 02:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration