MongoDB PHP function InsertMany() is not working - php

I am facing problem in MongoDB with PHP, I am using MongoDB InsertMany() function with the below code--
$document = array(array(
"title" => $_POST['title'],
"description" => $_POST['description'],
"likes" => $_POST['likes'],
"writenby" => $_POST['writtenby'],
"url" => $_POST['urllnk'],
), array("label1"=>"1","label2"=>"2"), array("label3"=>"3","label4"=>"4"));
$collection->insertMany($document);
I tried to insert data but the code is not working.
Thanks

Related

updateOrCreate() not updating but adding new

Trying to update inserted data. But it's not quite working. If the data in the $variable changed then updateOrCreate method is just creating a new row. But it's supposed to be update the existed column?
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "I am changing here",
];
Place::updateOrCreate($placeItems);
I changed the description column. And use updateOrCreate, but it's not update the id of description in. Insert it as new. The way i am using updateOrCreate is wrong?
UPDATED
I tried a way as mentioned in the answer below and test it.
$description = "new data";
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "old data",
];
Place::updateOrCreate([
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description,
], $placeItems);
But it still inserting as new column. not updating the ID of description in.
In your case you should specify parameters for updatedOrCreate.
The first parameter indicates the conditions for a match and second parameter specify which fields to update.
Place::updateOrCreate([ "website_id"=> self::WEBSITE_ID], [
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description]);
Read documentation here

How to update many fields at once in mongoDB PHP? [duplicate]

The following code should work. I could have missed something, but right now I have it as 2 separate update statements and have decided to ask here why this line isn't working.
$this->db->settings->update(array('_id' => $mongoID),
array(
'$set' => array('about' => $about),
'$set' => array('avatar' => $avatar)
)
);
Did I miss something when reading guides or is it only possible to do with separate update statements?
The third argument to MongoCollection::update is an array of options for the update operation.
$this->db->settings->update(
array('_id' => $mongoID),
array('$set' => array('about' => $about, 'avatar' => $avatar))
);

Add Organisation & Contact to Insightly and automatically link them

I am using a PHP library (https://github.com/Insightly/insightly-php) with great success for the Insightly API. More information on the Insightly API can be found here: https://api.insight.ly/v2.2/Help
My goal is to have an organisation and a contact added to Insightly on a form submission and to then link the two together. I can add the organisation and the contact without any issues but I am having troubles linking the two afterwards. When I add in the code to link the two it is only adding the organisation and not the contact.
Please view my code below:
$organization = $i->addOrganization($newOrganization);
$getOrganizationID = $i->getOrganization($company);
$id = json_decode($getOrganizationID, true);
$newContact = (object)array(
"FIRST_NAME" => $first_name,
"LAST_NAME" => $last_name,
"CONTACTINFOS" => array(
(object)array(
"TYPE" => "EMAIL",
"LABEL" => "WORK",
"DETAIL" => $email,
),
(object)array(
"TYPE" => "PHONE",
"LABEL" => "WORK",
"DETAIL" => $phone,
)
),
"LINKS" => array(
(object)array(
"ORGANISATION_ID" => $id[0]['ORGANISATION_ID'],
)
),
);
$contact = $i->addContact($newContact);
I had a faulty link in the getOrganization() function and have since fixed it.

get_comments not working properly after WordPress v4.4 update

I just found a wired thing on my website after v4.4 update. In my blog pages I use 2 functions to fetch comments.
First I use
wp_list_comments( array( "callback" => "checkout_comment", "type" => "comment") );
To fetch the comments only. Then I run a count check if any trackbacks exists by using
$trackback_count = get_comments( array(
'status' => 'approve',
'post_id'=> get_the_ID(),
'type'=> 'pings',
'count' => true)
);
and if the do exists the I show the trackbacks/pingsbacks like this
wp_list_comments( array( "callback" => "checkout_comment", "type" => "pings", "reply_text" => null, "format" => "html5") );
Now, after v4.4 update the comments are showing fine but the trackbacks list are not showing.
Can anyone tell me why? What I might need to change to fix this?

How to log dimension like AWS CloudWatch bundled metric

Can anyone explain how to use the AWS PHP SDK to log the metric in the style like the above screen.
I use the following PHP code but the select menu is showing "ELB: AvaliabiltyZone", how to make it show "Aggregated by AvaliabiltyZone"? What is the logic used here?
$response = $cw->put_metric_data("ELB", array(
array(
"MetricName" => "Latency",
"Dimensions" => array(
array("Name" => "AvaliabiltyZone" , "Value" => "us-east-1c")
),
"Timestamp" => "now",
"Value" => 1,
"Unit" => "None"
),
));
AvaliabiltyZone
You misspelled "AvailabilityZone"
This maybe won't answer the question, but it might fix some things...
$cw = new AmazonCloudWatch();
$cw->set_region('monitoring.'.$region.'amazonaws.com');
$res1 = $CW->put_metric_data('Sys/RDS' ,
array(array('MetricName' => 'Uptime' ,
'Dimensions' => array(array('Name' => 'AvaliabiltyZone',
'Value' => 'us-east-1c')),
'Value' => $Uptime,
'Unit' => 'Seconds')));
Click Here

Categories