I am using DynamoDB for a social app based on events, like-unlike attending-not_attending.
I am interested in finding out how can add or remove an item from a StringSet attribute in DynamoDB Item.
Here is the objects structure
"userId": {
"S": "69"
},
"fName": {
"S": "mfName"
},
"lName": {
"S": "mlName"
},
"picture": {
"S": "https://s3-us-west-2.amazonaws.com/users/mfName_1000049788.jpg"
},
"events": {
"M": {
"1502199358": {
"M": {
"created": {
"S": "1502199358.443022"
},
"eventId": {
"S": "-1"
},
"galleryId": {
"S": "1502199358"
},
"image": {
"S": "https://s3.amazonaws.com/events/public/clyp_1502199358.jpg"
},
"likes": {
"SS": [
"12",
"321",
"69"
]
},
"modified": {
"S": "1"
},
"video": {
"S": "n_p"
},
"videothumb": {
"S": "n_p"
}
}
}
}
}
and I would like to add or remove one entry in "likes" StringSet
"likes": {
"SS": [
"12",
"321",
"69"
]
},
accordingly a user like-unlike the event.
how can I do this?
I did not get able to update/edit item on third or 4th child level.
Here you can use this method to add/delete item from a string set on second child level.
AWSDynamoDB *dynamoDB = [AWSDynamoDB defaultDynamoDB];
AWSDynamoDBAttributeValue * itemToUpdate = [AWSDynamoDBAttributeValue new];
itemToUpdate.S = self.userID;
AWSDynamoDBUpdateItemInput *updateItemInput = [AWSDynamoDBUpdateItemInput new];
updateItemInput.tableName = #"MyTable";
updateItemInput.key= #{
#"userId" : itemToUpdate
};
NSArray * likesArray = [NSArray arrayWithObjects:#"12", nil];
AWSDynamoDBAttributeValue * awsDynamoDBAttributeValue = [AWSDynamoDBAttributeValue new];
awsDynamoDBAttributeValue.SS = likesArray;
AWSDynamoDBAttributeValueUpdate * valueUpdate = [AWSDynamoDBAttributeValueUpdate new];
valueUpdate.value = awsDynamoDBAttributeValue;
valueUpdate.action = AWSDynamoDBAttributeActionDelete;
updateItemInput.attributeUpdates =#{
#"likes":valueUpdate
};
[[dynamoDB updateItem:updateItemInput]
continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(#"The request failed. Error: [%#]", task.error);
}
if (task.result) {
//Do something with result.
}
return nil;
}];
-> for add an item
valueUpdate.action = AWSDynamoDBAttributeActionAdd;
-> for delete an item
valueUpdate.action = AWSDynamoDBAttributeActionDelete;
Hope it would help someone.
Related
I'm new to API Connect, and I haven't been able to find the correct mapping to pass from an array of objects to an object, evaluating its content.
I explain:
I have as input a json like this:
{
"methodCall": {
"methodName": {
"$": "ThisIsTheMethodName"
},
"params": {
"param": {
"value": {
"array": {
"data": {
"value": {
"struct": {
"member": [
{
"name": {
"$": "message"
},
"value": {
"string": {
"$": "Some text to send to client"
}
}
},
{
"name": {
"$": "phone"
},
"value": {
"string": {
"$": "9876543120124"
}
}
},
{
"name": {
"$": "date"
},
"value": {
"string": {}
}
},
{
"name": {
"$": "appid"
},
"value": {
"string": {
"$": "Application Identificator"
}
}
},
{
"name": {
"$": "costCenter"
},
"value": {
"string": {
"$": "102030"
}
}
},
{
"name": {
"$": "filled"
},
"value": {
"string": {
"$": "filledString"
}
}
}
]
}
}
}
}
}
}
}
}
}
and I need to generate this json output from the mapping:
{
"phoneNumberSMS":"983849780",
"message":"Some text to send to client",
"date": "2022-10-04T15:30:00",
"appId":"Application Identificator",
"costCenter":"102030",
"filled":"filledString" }
I have tried with the following configuration, but without success:
On the YAML
actions:
- set: output.phoneNumberSMS
foreach: input.methodCall.params.param.value.array.data.value.struct.member.value.string
from:
- input.methodCall.params.param.value.array.data.value.struct.member.name.$
- input.methodCall.params.param.value.array.data.value.struct.member.value.string.$
values: |-
var retValue1 = '';
if($(input.methodCall.params.param.value.array.data.value.struct.member.name.$) == 'phone'){
retValue1=input.methodCall.params.param.value.array.data.value.struct.member.value.string.$;
}
retValue1;
I appreciate your help !!
I solve this in two phases of mapping:
Create an array called members, where each node is of type member, which has name and value properties.
This 'members' array is the receiver of the data coming from the request.
In the second phase of the mapping, I took the output variable from the previous mapping (of type members) and assigned it to message.body.
This with the aim of getting rid of the field names with a dollar symbol ($), so the mapping will not give any error for not recognizing it.
i'm using elasticsearch-rails for a project, there is a combine search feature, all columns are in one table. I just write a custom search function, and the search dsl didn't work, can't have any results.
def self.combine_search_filter(remark=nil, sim_card_supplier_id=nil, work_mode=nil, operator_status=nil, platform_management_status=nil, online_status=nil, sim_card_set_id=nil, iccid_from=nil, iccid_to=nil, actived_at_from=nil, actived_at_to=nil, check_in_at_from=nil, check_in_at_to=nil, device_mac_from=nil, device_mac_to=nil)
response = __elasticsearch__.search(
"size": 1000,
"query": {
"filtered": {
"filter": {
"bool": {
"filter": [
{ "term": { "sim_card_supplier_id": sim_card_supplier_id } },
{ "term": { "work_mode": work_mode } },
{ "term": { "operator_status": operator_status } },
{ "term": { "platform_management_status": platform_management_status } },
{ "term": { "online_status": online_status } },
{ "term": { "sim_card_set_id": sim_card_supplier_id } }
{ "range": { "iccid": { "from": iccid_from, "to": iccid_to }}},
{ "range": { "check_in_at": { "from": check_in_at_from, "to": check_in_at_to }}},
{ "range": { "actived_at": { "from": actived_at_from, "to": actived_at_to }}},
{ "range": { "device_mac": { "from": device_mac_from, "to": device_mac_to }}}
]
}
}
}
}
)
end
and the params maybe pass nil, how can i do that make the search dsl valid?
I would rather suggest you to use searchkick gem for rails which makes elastic search as simple as that and makes your search more intelligent and queries simple.
My bad, i just figure this out, ruby keyword function should be like this:
def self.combine_search_filter(options = {})
response = __elasticsearch__.search(
"size": 1000,
"query": {
"filtered": {
"filter": {
"bool": {
"filter": [
{ "term": { "sim_card_supplier_id": 104 } },
{ "term": { "work_mode": options[:work_mode] } },
{ "term": { "operator_status": options[:operator_status] } },
{ "term": { "platform_management_status": options[:platform_management_status] } },
{ "term": { "online_status": options[:online_status] } },
{ "term": { "sim_card_set_id": 76 } },
{ "range": { "iccid": { "from": options[:iccid_from], "to": options[:iccid_to] }}},
{ "range": { "check_in_at": { "from": options[:check_in_at_from], "to": options[:check_in_at_to] }}},
{ "range": { "actived_at": { "from": options[:actived_at_from], "to": options[:actived_at_to] }}},
{ "range": { "device_mac": { "from": options[:device_mac_from], "to": options[:device_mac_to] }}}
]
}
}
}
}
)
end
this search will have the correct result. The options[:key] may be nil will cause the wrong result, so i'm gonna delete the nil key of the dsl hash, then pass it to search()
I have following JSON response which has been stored in NSMutableDictonary. I want to addition of all the price of special_item.
{
"order_id": "1",
"order_name": "xyz",
"order_item": [
{
"item_id": "1",
"item_name": "myone",
"special_item": [
{
"s_item_id": "1",
"price": "10"
},
{
"s_item_id": "2",
"price": "100"
}
]
},
{
"item_id": "2",
"item_name": "mytwo",
"special_item": [
{
"s_item_id": "11",
"price": "15"
},
{
"s_item_id": "22",
"price": "110"
}
]
}
]
}
Is it possible to do addition of all the price using NSPredicate ? or How can I get array of all the price values using NSPredicate?(e.g : [#10,#100,#15,#110])
Thank you!
It is so simple
you can try below code
NSArray *arr = [dix valueForKeyPath:#"order_item.special_item.price"];
long total = 0;
for (id price in arr) {
if ([price isKindOfClass:[NSArray class]]) {
total += [[price valueForKeyPath:#"#sum.self"] longValue];
}
else {
total += [price longValue];
}
}
NSInteger *total=0;
NSArray *arr=[NSDictionary objectForKey=#"order_item"];
for(NSDictionary *dic in arr){
NSArray *array=[dic objectForKey=#"special_item"];
for(NSDictionary *d in array){
total=total+[[d objectForKey=#"price"] intValue];
}
}
NSLog("Total:- %d",total);
I've got a JSON Request that I'm able to add to an NSDictionary but I'm unable to access part of the JSON string. Here is a sample
{
"Resp": {
"Success": "True",
"who": {
"userid": 234,
},
"students": [
{
"ID": 1,
"name": John
},
{
"ID": 2,
"name": Jane
}
],
}
}
I am storing the data in an NSMutableDictionary and then passing that to my function which should run through each student and process them accordingly.
Here is what I've got so far and it's not working:
-(void)foo:(NSMutableDictionary*)json {
NSArray *students = json[#"students"];
for(NSMutableDictionary *student in students) {
NSLog(#"student id: %#", student[#"ID"]);
}
}
When debugging I can see the JSON object and students belongs under Resp as a value.
First of all, check your JSON on the validity http://jsonlint.com . It corrected your JSON with next modifications:
{
"Resp": {
"Success": "True",
"who": {
"userid": 234
},
"students": [
{
"ID": 1,
"name": "John"
},
{
"ID": 2,
"name": "Jane"
}
]
}
}
Then you should access your elements in right way:
- (void)foo:(NSMutableDictionary *)json {
NSArray *students = json[#"Resp"][#"students"];
for(NSDictionary *student in students) {
NSLog(#"student id: %#", student[#"ID"]);
}
}
For now it should be working.
i am working one facebook intrgation project in ios,iphone
so i am using me?fields=posts on browser is working properly
i means on this link developer account
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dposts
but when i am using me?fields=posts in xcode this only return a old data not all data
here is my code so please give me solution where i am doing mistake
[FBRequestConnection startWithGraphPath:#"me?fields=posts"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Results: %#", result);
NSArray *post = [result valueForKey:#"posts"];
NSArray *mainData = [post valueForKey:#"data"];
/// NSLog(#"Results: show image>>>>>>> %#", [mainData valueForKey:#"picture"]);
//
NSArray *picturedata =[mainData valueForKey:#"picture"];
NSLog(#"%#",picturedata);
Here i attacha a image link also please check
image 1
in Graph api data is
{
"posts": {
"data": [
{
"id": "100005440749818_240650716126285",
"from": {
"name": "Birjesh Sharma",
"id": "100005440749818"
},
"message": "Hello\r\n\r\n\r\n",
"picture": "https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=278318608948142&v=1&size=z&cksum=9c977855a08e5bde268444a1ab24a254&src=https%3A%2F%2Fraw.github.com%2Ffbsamples%2Fios-3.x-howtos%2Fmaster%2FImages%2Fiossdk_logo.png",
"link": "https://developers.facebook.com/ios",
"name": "Facebook SDK for iOS",
"caption": "Build great social apps and get more installs.",
"description": "The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.",
"icon": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/small/icon-app.png",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100005440749818/posts/240650716126285"
},
{
"name": "Like",
"link": "https://www.facebook.com/100005440749818/posts/240650716126285"
}
],
"privacy": {
"description": "Friends",
"value": "ALL_FRIENDS",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "link",
"status_type": "app_created_story",
"application": {
"name": "Feed Dialog How To",
"id": "278318608948142"
},
"created_time": "2014-04-26T12:59:15+0000",
"updated_time": "2014-04-26T12:59:15+0000"
},
{
"id": "100005440749818_240650712792952",
"from": {
"name": "Birjesh Sharma",
"id": "100005440749818"
},
"message": "Hello\r\n\r\n\r\n",
"picture": "https://fbexternal-a.akamaihd.net/app_full_proxy.php?app=278318608948142&v=1&size=z&cksum=9c977855a08e5bde268444a1ab24a254&src=https%3A%2F%2Fraw.github.com%2Ffbsamples%2Fios-3.x-howtos%2Fmaster%2FImages%2Fiossdk_logo.png",
"link": "https://developers.facebook.com/ios",
"name": "Facebook SDK for iOS",
"caption": "Build great social apps and get more installs.",
"description": "The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.",
"icon": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/small/icon-app.png",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100005440749818/posts/240650712792952"
},
{
"name": "Like",
"link": "https://www.facebook.com/100005440749818/posts/240650712792952"
}
],
"privacy": {
"description": "Friends",
"value": "ALL_FRIENDS",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "link",
"status_type": "app_created_story",
"application": {
"name": "Feed Dialog How To",
"id": "278318608948142"
},
"created_time": "2014-04-26T12:59:14+0000",
"updated_time": "2014-04-26T12:59:14+0000"
},
{
"id": "100005440749818_240643612793662",
"from": {
"name": "Birjesh Sharma",
"id": "100005440749818"
},
"message": "Hello how are you",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100005440749818/posts/240643612793662"
},
{
"name": "Like",
"link": "https://www.facebook.com/100005440749818/posts/240643612793662"
}
],
"privacy": {
"description": "Friends",
"value": "ALL_FRIENDS",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "status",
"status_type": "mobile_status_update",
"application": {
"name": "Batch Requests How To",
"id": "216458921816803"
},
"created_time": "2014-04-26T12:20:43+0000",
"updated_time": "2014-04-26T12:20:43+0000"
},
{
"id": "100005440749818_240368252821198",
"from": {
"name": "Birjesh Sharma",
"id": "100005440749818"
},
"story": "Birjesh Sharma added a new photo.",
"picture": "https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10155869_240368246154532_637168545169195821_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=240368246154532&set=a.170520606472630.1073741830.100005440749818&type=1&relevant_count=1",
"name": "HelloFBSample Photos",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100005440749818/posts/240368252821198"
},
{
"name": "Like",
"link": "https://www.facebook.com/100005440749818/posts/240368252821198"
}
],
"privacy": {
"description": "Only Me",
"value": "SELF",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "photo",
"status_type": "added_photos",
"object_id": "240368246154532",
"application": {
"name": "HelloFBSample",
"namespace": "fbsdktemplateapp",
"id": "355198514515820"
},
"created_time": "2014-04-25T13:26:06+0000",
"updated_time": "2014-04-25T13:26:06+0000"
},
{
"id": "100005440749818_240333912824632",
"from": {
"name": "Birjesh Sharma",
"id": "100005440749818"
},
"message": "Post by nishant",
"picture": "https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10155899_240333846157972_3108893745639530212_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=240333846157972&set=a.239581289566561.1073741833.100005440749818&type=1&relevant_count=1",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100005440749818/posts/240333912824632"
},
{
"name": "Like",
"link": "https://www.facebook.com/100005440749818/posts/240333912824632"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "photo",
"status_type": "added_photos",
"object_id": "240333846157972",
"created_time": "2014-04-25T10:33:45+0000",
"updated_time": "2014-04-25T10:33:45+0000",
"likes": {
"data": [
{
"id": "100005440749818",
"name": "Birjesh Sharma"
}
],
"paging": {
"cursors": {
"after": "MTAwMDA1NDQwNzQ5ODE4",
"before": "MTAwMDA1NDQwNzQ5ODE4"
}
}
}
},
and when i am using this graph api in xcode the data show this
Results: {
id = 100005440749818;
posts = {
data = (
{
"created_time" = "2014-04-17T14:13:12+0000";
from = {
id = 100005440749818;
name = "Birjesh Sharma";
};
id = "100005440749818_238353183022705";
link = "https://www.facebook.com/nitin.dhiran.1?fref=nf_fr";
picture = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/c0.9.50.50/p50x50/10262125_697172320343788_6250762651875413687_t.jpg";
privacy = {
value = "";
};
"status_type" = "approved_friend";
story = "Birjesh Sharma is now friends with Nitin Dhiran and 3 other people.";
"story_tags" = {
0 = (
{
id = 100005440749818;
length = 14;
name = "Birjesh Sharma";
offset = 0;
type = user;
}
);
35 = (
{
id = 100001530793389;
length = 12;
name = "Nitin Dhiran";
offset = 35;
type = user;
}
);
52 = (
{
id = 100008058972523;
length = 14;
name = "Hemant Kumar";
offset = 52;
type = user;
},
{
id = 100001307401657;
length = 14;
name = "Chetan Pushpad";
offset = 52;
type = user;
},
{
id = 100002675972915;
length = 14;
name = "Vipin Shukla";
offset = 52;
type = user;
}
);
};
type = link;
"updated_time" = "2014-04-17T14:13:12+0000";
},
{
"created_time" = "2014-03-27T07:21:35+0000";
from = {
id = 100005440749818;
name = "Birjesh Sharma";
};
id = "100005440749818_232528183605205";
privacy = {
value = "";
};
"status_type" = "approved_friend";
story = "Birjesh Sharma is now friends with Ishant Tiwari and Viraj Dongre.";
"story_tags" = {
0 = (
{
id = 100005440749818;
length = 14;
name = "Birjesh Sharma";
offset = 0;
type = user;
}
);
35 = (
{
id = 100000329153640;
length = 13;
name = "Ishant Tiwari";
offset = 35;
type = user;
}
);
53 = (
{
id = 100002123975517;
length = 12;
name = "Viraj Dongre";
offset = 53;
type = user;
}
);
};
type = status;
"updated_time" = "2014-03-27T07:21:35+0000";
}
);
paging = {
next = "https://graph.facebook.com/100005440749818/posts?access_token=CAAUTJQ2n428BAN3p9kiFFMZA7ZBlDO2NTIddfkUNJdbqT32kfbVs8GJaORmJXTF4NnF6RUtIwwp0H0vTzS147lxFF3runTHbupqZBkxbyl73dV5URHwvZA78CqVXWJggaofAy2JfZBf1GCoUQfNCyN0TAJaEnnsLn9ea6d2wLtDAataFtxGyFQJwZBWajQOiIwtidXqliCFV8haorHgfE4ahdbpO5n7oUZD&limit=25&until=1395904894";
previous = "https://graph.facebook.com/100005440749818/posts?access_token=CAAUTJQ2n428BAN3p9kiFFMZA7ZBlDO2NTIddfkUNJdbqT32kfbVs8GJaORmJXTF4NnF6RUtIwwp0H0vTzS147lxFF3runTHbupqZBkxbyl73dV5URHwvZA78CqVXWJggaofAy2JfZBf1GCoUQfNCyN0TAJaEnnsLn9ea6d2wLtDAataFtxGyFQJwZBWajQOiIwtidXqliCFV8haorHgfE4ahdbpO5n7oUZD&limit=25&since=1397743992&__previous=1";
};
};
}
The posts list is divided into several pages, and you only got the first page. To get all the posts, use the URL in results.posts.paging.next.
You can use this FBSDKGraphRequest paging extension to do that for you.