I want to Search a value in an array Like
`[_id] => MongoId Object (
[$id] => 511f4ce622efc34f15000001
)
[metadata] => Array (
[filename] => 6410-funny_face.gif
[parrent] => myfolder/newfolder2
[user] => Array ( >>>>>>>> i need to fetch all users
[root] => 7
[admin] => 7
[user] => 0
)
[group] => Array (
[23] => 2
)
)
[filename] => 6410-funny_face.gif
[uploadDate] => MongoDate Object (
[sec] => 1361005798
[usec] => 799000
)
[length] => 3083
[chunkSize] => 262144
[md5] => eb3846f78f461165e5bf59a05707edd1`
I need to find the user's key and value in PHP or MongoShell
im using db.collection.find(array(metadata.filename: 6410-funny_face.gif)); gives the correct answer but while in finding db.collection.find(array(metadata.user: array(7)));
db.collection.find({"metadata.user.root":7})
This should work if I understand your question.
Related
I am trying to send a mail using the SendGrid PHP API library. It worked when I tried it yesterday but today the reponse just has zero information:
SendGrid\Response Object
(
[statusCode:protected] => 0
[body:protected] =>
[headers:protected] => Array
(
[0] =>
)
)
The following object is being used in the \SendGrid\SendGrid()->send() method:
SendGrid\Mail\Mail Object
(
[from:SendGrid\Mail\Mail:private] => SendGrid\Mail\From Object
(
[name:SendGrid\Mail\EmailAddress:private] => test1
[email:SendGrid\Mail\EmailAddress:private] => test#example.com
[substitutions:SendGrid\Mail\EmailAddress:private] =>
[subject:SendGrid\Mail\EmailAddress:private] =>
)
[subject:SendGrid\Mail\Mail:private] => SendGrid\Mail\Subject Object
(
[subject:SendGrid\Mail\Subject:private] => this is a test
)
[contents:SendGrid\Mail\Mail:private] => Array
(
[0] => SendGrid\Mail\Content Object
(
[type:SendGrid\Mail\Content:private] => text/html
[value:SendGrid\Mail\Content:private] =>
<h1>sending mails</h1>
)
)
[attachments:SendGrid\Mail\Mail:private] =>
[reply_to:SendGrid\Mail\Mail:private] =>
[personalization:SendGrid\Mail\Mail:private] => Array
(
[0] => SendGrid\Mail\Personalization Object
(
[tos:SendGrid\Mail\Personalization:private] => Array
(
[0] => SendGrid\Mail\To Object
(
[name:SendGrid\Mail\EmailAddress:private] => mr test
[email:SendGrid\Mail\EmailAddress:private] => testtest#example.com
[substitutions:SendGrid\Mail\EmailAddress:private] =>
[subject:SendGrid\Mail\EmailAddress:private] =>
)
)
[ccs:SendGrid\Mail\Personalization:private] => Array
(
[0] => SendGrid\Mail\Cc Object
(
[name:SendGrid\Mail\EmailAddress:private] =>
[email:SendGrid\Mail\EmailAddress:private] => testtest1#example.com
[substitutions:SendGrid\Mail\EmailAddress:private] =>
[subject:SendGrid\Mail\EmailAddress:private] =>
)
)
[bccs:SendGrid\Mail\Personalization:private] =>
[subject:SendGrid\Mail\Personalization:private] =>
)
)
)
Obviously I used correct addresses in the tos and ccs sections.
Is something wrong with the sent object?
Apart from the code if there are any other problems in sending mail the send-grid library remains silent without throwing any exceptions and just returns the response 0. I would suggest you to
visit this link
In php-http-client\lib create a folder Exception.
Copy lib/Exception/InvalidRequest.php into the folder.
Modify lib/Client.php
These modifications are to throw appropriate exceptions which will help you to find what could be the problem in your case and be able to take it further.
Array from collection looks like this.
$result = $collection->find();
Array
(
[0] => Array
(
[_id] => MongoDB\BSON\ObjectId Object
(
[oid] => 5c52b90454851c44aa2987e2
)
[name] => Array
(
[date] => 2019-01-31 10:59:48
[value] => DESKTOP-TODTF5E
)
[network_addresses] => Array
(
[0] => Array
(
[ip_1] => 12.21.134
[ip_2] => 50
[mac] => xx:xx:xx:xx:xx:xx
)
[1] => Array
(
[ip_1] => 192.168.0
[ip_2] => 2
[mac] => yy:yy:yy:yy:yy:yy
)
)
)
)
I can find if some mac exist in specific row of sub array like this:
$result = $collection->find(["network_addresses.0.mac" =>
"xx:xx:xx:xx:xx:xx"]);
But I need to check if certain mac exists in any row of subarray, so instead of row index 0 I need to put some asterix or something.
How to do that ?
$query = (new Query)->select(["name"])
->from(['db_name','collection_name'])
->where(["network_addresses" => [ '$elemMatch' =>['mac' => "xx:xx:xx:xx:xx:xx"]]]);
$results = $query->all();
I'm using the Salesforce Force.com REST API. I need to determine which Products (Product2) are associated with Opportunities (Opportunity). Thus far, I've been unable to make the connection.
In the Salesofrce UI, opportunities can be associated with pricebooks and products. Pricebooks contain products, but it is also possible to associate products with an opportunity directly.
Querying an opportunity via the API yields the following:
Array
(
[0] => Array
(
[attributes] => Array
(
[type] => Opportunity
[url] => /services/data/v33.0/sobjects/Opportunity/xxxxxxxxxxxxxxxx
)
[Id] => xxxxxxxxxxxxxxxx
[IsDeleted] =>
[AccountId] => xxxxxxxxxxxxxxxxx
[Name] => Some Name
[Description] =>
[StageName] => Closed Won
[Amount] => 650
[Probability] => 100
[CloseDate] => 2012-04-12
[Type] => New Business
[NextStep] => A string
[LeadSource] => something
[IsClosed] => 1
[IsWon] => 1
[ForecastCategory] => Closed
[ForecastCategoryName] => Closed
[CampaignId] =>
[HasOpportunityLineItem] => 1
[Pricebook2Id] => xxxxxxxxxxxxxxxxxxxxx
[OwnerId] => xxxxxxxxxxxxxxxxxxx
[CreatedDate] => 2012-12-30T20:17:35.000+0000
[CreatedById] => xxxxxxxxxxxxxxxxxxxxxxxxxxx
[LastModifiedDate] => 2015-05-22T15:20:18.000+0000
[LastModifiedById] => xxxxxxxxxxxxxxxxxxxxxxxx
[SystemModstamp] => 2015-05-22T15:20:18.000+0000
[LastActivityDate] =>
[FiscalQuarter] => 1
[FiscalYear] => 2015
[Fiscal] => 2015 1
[LastViewedDate] => 2015-06-03T14:38:03.000+0000
[LastReferencedDate] => 2015-06-03T14:38:03.000+0000
[SyncedQuoteId] =>
[Type_of_Deal__c] => Monthly Contract Count
[Number_of_Contracts__c] => 999
[Fee_Per_Contract__c] => 999
[Installation_Fee__c] =>
[Roof_Top_Fee__c] =>
[LID__LinkedIn_Company_Id__c] =>
[inclusion_type__c] => inclusion type
[Total_Contract_Term__c] => 999
[Monthly_Value_of_Fee_Per_Contract__c] => 999
[Total_Value_of_Fee_Per_Contract__c] => 999
[Total_Value_of_Roof_Top_Fee__c] => 0
[Monthly_Fidels_Revenue__c] => 999
[Total_Value_of_Deal__c] => 999
[Number_of_Roof_Tops__c] =>
[Monthly_Value_of_Roof_Top_Fee__c] => 0
[Installation_Date__c] => 2012-01-01
[Reason_if_Lost__c] =>
[Total_Monthly_Revenue__c] => 999
[Existing_Agency__c] => Service Group
[Number_of_Contracts_in_Last_Batch__c] => 999
[Agent_Name__c] => John Smith
[Total_Value_of_Agency_Revenue__c] => 9999
[Contract_Start_Date__c] => 2012-01-01
[Batch_Received__c] => Yes
[Administrator__c] =>
[Per_Contract__c] => 999
[Integration_type__c] =>
[Last_Batch_ID__c] =>
[Last_Batch_Date__c] =>
)
)
From which you can see that no Product2 data is available. There is however, a Pricebook2Id. One might assume that querying that specific pricebook would yield information on which products are associated with it. However, querying a specific pricebook yields the following:
Array
(
[0] => Array
(
[attributes] => Array
(
[type] => Pricebook2
[url] => /services/data/v33.0/sobjects/Pricebook2/xxxxxxxxxxxx
)
[Id] => xxxxxxxxxxxxxxxxxxxx
[IsDeleted] =>
[Name] => Company Price Book
[CreatedDate] => 2011-11-14T18:36:23.000+0000
[CreatedById] => xxxxxxxxxxxxxxxxxxx
[LastModifiedDate] => 2011-11-14T18:36:23.000+0000
[LastModifiedById] => xxxxxxxxxxxxxxxxxxxxxxx
[SystemModstamp] => 2011-11-14T18:36:23.000+0000
[LastViewedDate] => 2015-06-04T19:41:20.000+0000
[LastReferencedDate] => 2015-06-04T19:41:20.000+0000
[IsActive] => 1
[Description] =>
[IsStandard] =>
)
)
As you can see, no information about products is available from the pricebook. So my question is:
How do I determine which products are associated with opportunities using the Salesforce Force.com REST API?
There is an object called 'Opportunity Product'. you need to get that object as well and link the proper opportunity to product.
It's a many to many relation and not one to many so more than one product might be related to each opportunity and vise versa.
On a fresh install of sugarcrm 6.5 CE, I created a custom module "Groupes", with a many-to-many relationship to Accounts.
I added a record in Accounts, and one in "Groupes", and linked them together.
My goal is to use REST v4 to retrieve records in "Groupes", and the related Account records.
Using get_entry_list, I tried the following :
//retrieve records ----------------------------------------
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => "Accounts",
//The SQL WHERE clause without the word "where".
'query' => "",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => "0",
//Optional. The list of fields to be returned in the results
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name
'link_name_to_fields_array' => array(
array(
'name' => 'offi1_groupes',
'value' => array(
'id',
'name',
),
),
),
//The maximum number of results to return.
'max_results' => '10000',
//To exclude deleted records
'deleted' => 0,
//If only records marked as favorites should be returned.
'Favorites' => false,
);
$get_entry_list_result = call("get_entry_list", $get_entry_list_parameters, $url);
Below you can see what I get : as you can see, the "Groupes" record are not fetched. Any clue on what went wrong ?
stdClass Object
(
[result_count] => 1
[total_count] => 1
[next_offset] => 1
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
)
[name] => stdClass Object
(
[name] => name
[value] => Pharmacie témoin
)
)
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => offi1_groupes
[records] => Array
(
)
)
)
)
)
)
First Get Account ID
self::$soap->get_entry_list(self::$sessionId, 'Accounts', "name='NAME'");
$acc_id = $response->entry_list[0]->id;
Get Groups ID From Relations
$get_relationships_result = self::$soap->get_relationships(self::$sessionId,"Accounts",$acc_id,"Groupes");
$groups_id = $get_relationships_result->ids[0]->id;
back and get Related Groups Information
self::$soap->get_entry_list(self::$sessionId, 'Groupes', "Groupes.id=$groupes_id");
I can get desired data using facebook api like interest, movies etc. Which comes in below format.
Array
(
[data] => Array
(
[0] => Array
(
[category] => Movie
[name] => 3 Idiots Movie
[created_time] => 2012-05-11T13:22:34+0000
[id] => 441170255909978
)
[1] => Array
(
[category] => Movie
[name] => Harry Potter
[created_time] => 2011-04-11T05:44:14+0000
[id] => 156794164312
)
[2] => Array
(
[category] => Movie
[name] => Official Narnia: Voyage of the Dawn Treader
[created_time] => 2011-03-10T18:26:57+0000
[id] => 190647217857
)
[3] => Array
(
[category] => Movie general
[name] => Harry Porter
[created_time] => 2011-03-10T18:26:57+0000
[id] => 360697777345
)
How can I get details whic gives only movies and ID so that I can store in database?
You can do something of the following form:
foreach (Array['data'] as $var)
{
$ID=$var['id'];
$Name=$var['name'];
}
Note: In Array['data'], Array will be the name of the variable that you are saving this data in.