I want to delete an item from array of items where if some condition gets true.
For eg:
I have 1000's of records which each have caseDetails array and inside that I have many items.
I want to pass in a caseId and delete any caseDetails items that match that id.
Below is the MongoDB data for explanation let say I have two data for example now I want that if caseId=24894006(That i have passed) exits(Not to write new query) in the DB then it should get deleted.
1)First DB data
{
"_id": "60f8fcbe8f67d30784c45561",
"messageType": "e",
"sendDate": "2021-07-22T05:06:04.023Z",
"assigneeId": 600003,
"customerId": 58004,
"subject": "Email Test 1[#24894006]",
"mailAnswered": false,
"hasAttachments": false,
"caseDetails": [
{
"caseId": 24894006,
"employeeId": 600003
},
{
"caseId": 34894006,
"employeeId": 600003
},
{
"caseId": 44894006,
"employeeId": 600003
}
]
},
{
"_id": "60f8fcbe8f67d30784c45561",
"messageType": "e",
"sendDate": "2021-07-22T05:06:04.023Z",
"assigneeId": 600003,
"customerId": 58004,
"subject": "Email Test 1[#24894006]",
"mailAnswered": false,
"hasAttachments": false,
"caseDetails": [
{
"caseId": 24894006,
"employeeId": 600003
},
{
"caseId": 34894006,
"employeeId": 600003
},
{
"caseId": 44894006,
"employeeId": 600003
}
]
}
So as per above example the output in DB should be like:
{
"_id": "60f8fcbe8f67d30784c45561",
"messageType": "e",
"sendDate": "2021-07-22T05:06:04.023Z",
"assigneeId": 600003,
"customerId": 58004,
"subject": "Email Test 1[#24894006]",
"mailAnswered": false,
"hasAttachments": false,
"caseDetails": [
{
"caseId": 34894006,
"employeeId": 600003
},
{
"caseId": 44894006,
"employeeId": 600003
}
]
},
{
"_id": "80f8fcbe8f67d30784c45561",
"messageType": "e",
"sendDate": "2021-07-22T05:06:04.023Z",
"assigneeId": 600003,
"customerId": 58004,
"subject": "Email Test 1[#24894006]",
"mailAnswered": false,
"hasAttachments": false,
"caseDetails": [
{
"caseId": 54894006,
"employeeId": 600003
},
{
"caseId": 64894006,
"employeeId": 600003
}
]
}
From caseDetails caseId = 24894006(Whole object)
I have also coded:
#Override
public List<Email> unlinkMessageCaseDetailsByCaseId(MessageFilter messageFilter) {
Criteria finalCriteria = handleCriteria(messageFilter);
Query query = query(finalCriteria);
// Update update = new Update().pull("caseDetails", Collections.singletonMap("caseId", messageFilter.getCaseId()));
List<Email> uMono = mongoTemplate.find(query, Email.class).collectList().block();
return uMono;
}
This is the repository I'm using
#MongoRepository
public interface EmailRepository
extends ReactiveCrudRepository<Email, String>,
MessageRepositoryCustom {
}
I am calling API and getting below output but from the output and i want to find the key based on value input and my input value is "vpc-tz" how to achieve this in ansible using json_query?
{
"json": {
"allScopes": [
{
"
"clusters": {
"clusters": [
{
"cluster": {
"clientHandle": "",
"type": {
"name": "ClusterComputeResource"
},
"universalRevision": 0,
"vsmUuid": "423B1819-9495-4F10-A96A-6D8284E51B29"
}
}
]
},
"controlPlaneMode": "UNICAST_MODE",
"description": "",
"extendedAttributes": [
],
"id": "vdnscope-6",
"isTemporal": false,
"isUniversal": false,
"name": "vpc-tz",
"nodeId": "85e0073d-0e5a-4f04-889b-42df771aebf8",
"objectId": "vdnscope-6",
"objectTypeName": "VdnScope",
"revision": 0,
"type": {
"name": "VdnScope"
},
"universalRevision": 0,
"virtualWireCount": 0,
"vsmUuid": "423B1819-9495-4F10-A96A-6D8284E51B29"
},
]
}
}
Here is a query which works:
json.allScopes[?name=='vpc-tz'].name
I am trying to do a get request using elasticsearch which needs to get the data with respect to its Popularity/ rating. So I followed this Link
. I set the rating of my item by using the below one,
#1 http://localhost:9200/cars/car/_rank_eval
above is the Api which is used to create _rank_eval using postman ,
Below is my Body content ,
{
"requests": [
{
"id": "horsepower",
"request": {
"query": {
"match": {
"horsepower": "68"
}
}
},
"ratings": [
{
"_index": "cars",
"_id": "25",
"rating": 10
},
{
"_index": "cars",
"_id": "119",
"rating": 1
},
{
"_index": "cars",
"_id": "52",
"rating": 2
}
]
}
],
"metric": {
"precision": {
"relevant_rating_threshold": 1,
"ignore_unlabeled": false
}
}
}
Steps i did so far ,
1 . Created database with dumb data's in MySql
2 . Transferred my db data's to ElasticSearch using loadstash
3 . Set some rating's to my data
so what are all the next steps , did i miss anything .. I need some clarification/help on this .
So I have some JSON data that I want to find the items that appear more than once within a given product node. See sample data below.
For example, "item": "UT9908" is likely to appear more than once within a given "line" array. I need to select a list of these items and the count of how many there are within a given product.line array. Im using Linqpad and the code Im starting with, at least gets me to the point of getting a list of products. What I really need is a list of items that appear more than once WITHIN a given product.line array. How can I get that list?
What I get in the code below is an overall list of items and their count. How can I count WITHIN the line array?
var jsonPath = #"d:\temp\1Warehouse_temp_DATA.jsonbak";
JObject o1 = JObject.Parse(File.ReadAllText(jsonPath));
var deliveries = (from a in o1["order"].Children()["delivery"] select a).ToList();
var product_lines = (from a in deliveries.Children()["product"].Children()["line"] select a).ToList();
//product_lines.Dump();
var items_list = (from a in product_lines.Children()["model_accessory"]
group a by a["item"] into g1 where g1.Count () > 0
select new {item_name = g1.Key, cnt = g1.Count ()} )
.ToList();
items_list.Dump();
{
"order": [
{
"location": "TTY",
"osn": "1888TYHHIO",
"order_type": null,
"osn_status": "Delivered",
"order_date": "03012017",
"customer_name": "234234 test dr",
"customer_tol_account": null,
"customer_phone": "234234234",
"freight_terms": "PREPAID & CHARGE",
"shipping_instructions": "PH 8747474747",
"shipping_method": "",
"additional_service": "",
"tpoints": "1.9",
"delivery": [
{
"delivery_ad": "",
"osn_type": "TTU",
"customer_po_number": "234234",
"rap": "ONOWR",
"zip_group": "TYTYY",
"delivery_date": "04132017",
"delivery_name": "234 ghhhtol",
"delivery_address_1": "234 tol fr",
"delivery_address_2": "031807",
"delivery_city": "Somewhere",
"delivery_state": "Idaho",
"delivery_zip": "111223",
"delivery_phone": [
{
"phone_number": "345345345"
},
{
"phone_number": ""
}
],
"last_updated_date": "",
"product": [
{
"vendor": "UURL",
"shipment_number": "",
"ship_date": "",
"customer_tracking_number": "",
"line": [
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "M",
"item": "TTP99874",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
},
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "A",
"item": "UT9908",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
}
}
}
}
}
I'm not sure that I understand right, but anyway:
to do this, you have to deserialize your JSON to .NET object and then apply some LINQ queries to get required info.
Just something like the following:
Create the objects (I just missed all fields except needed):
public class OrderClass
{
/* all other properties... */
public string location { get; set; }
public DeliveryClass[] delivery { get; set; }
}
public class DeliveryClass
{
/* all other properties... */
public ProductClass[] product { get; set; }
}
public class ProductClass
{
/* all other properties... */
public LineClass[] line { get; set; }
/* add a method which returns a count of specific lines*/
public int LineSpecificCount(string s)
{
return this.line.Count(l => l.model_accessory.item.Equals(s));
}
}
public class LineClass
{
/* all other properties... */
public model_accessoryClass model_accessory { get; set; }
}
public class model_accessoryClass
{
/* all other properties... */
public string item { get; set; }
public string item_type { get; set; }
}
Then:
// get your all orders
OrderClass[] myOrders = JsonConvert.DeserializeObject<OrderClass[]>(o1["order"].ToString());
// get orders where item == "UT9908"
OrderClass[] ordersWithSpecificLine = myOrders.Where(o => o.delivery.Any(d => d.product.Any(p => p.line.Any(l => l.model_accessory.item.Equals("UT9908"))))).ToArray();
// get all lines in all orders where item == "UT9908"
LineClass[] lines = myOrders.SelectMany(o => o.delivery.SelectMany(d => d.product.SelectMany(p => p.line.Where(l => l.model_accessory.item.Equals("UT9908"))))).ToArray();
EDITED:
// get all products
ProductClass[] myproducts = orders1.SelectMany(o => o.delivery.SelectMany(d => d.product)).ToArray();
// and now you can access a count something like
ProductClass[] productsWithSpecificLine = myproducts.Where(p => p.LineSpecificCount("UT9908") > 0).ToArray();
// productsWithSpecificLine[0].LineSpecificCount("UT9908") == 2
// productsWithSpecificLine[1].LineSpecificCount("UT9908") == 1
P.S. I have edited your JSON due to some errors inside its structure, and also have added additional line items:
{
"order": [{
"location": "TTY",
"osn": "1888TYHHIO",
"order_type": null,
"osn_status": "Delivered",
"order_date": "03012017",
"customer_name": "234234 test dr",
"customer_tol_account": null,
"customer_phone": "234234234",
"freight_terms": "PREPAID & CHARGE",
"shipping_instructions": "PH 8747474747",
"shipping_method": "",
"additional_service": "",
"tpoints": "1.9",
"delivery": [{
"delivery_ad": "",
"osn_type": "TTU",
"customer_po_number": "234234",
"rap": "ONOWR",
"zip_group": "TYTYY",
"delivery_date": "04132017",
"delivery_name": "234 ghhhtol",
"delivery_address_1": "234 tol fr",
"delivery_address_2": "031807",
"delivery_city": "Somewhere",
"delivery_state": "Idaho",
"delivery_zip": "111223",
"delivery_phone": [{
"phone_number": "345345345"
},
{
"phone_number": ""
}],
"last_updated_date": "",
"product": [{
"vendor": "UURL",
"shipment_number": "",
"ship_date": "",
"customer_tracking_number": "",
"line": [{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "M",
"item": "TTP99874",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
},
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "A",
"item": "UT9908",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
},
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "B",
"item": "UT9908",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
}]
},
{
"vendor": "UURL",
"shipment_number": "",
"ship_date": "",
"customer_tracking_number": "",
"line": [{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "Z",
"item": "TTP99874",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
},
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "X",
"item": "UT9908",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
},
{
"line_number": "",
"line_status": "",
"model_accessory": {
"crated_indicator": "",
"item_type": "Y",
"item": "UT9909",
"product_type": "",
"anti_tip_indicator": "",
"product_weight": "",
"nmfc": "",
"carton_code": "",
"quantity": "1"
}
}]
}]
}]
}]
}
hihi i am doing a project regarding ajax (xmlHttRequest),
how am i going to call the title in the note session, because normally if you call start year is like, detail = eval....
then for loop it
inside should be
var start year=""
startyear += ...[i].startyear
something like this, but how am i going to call the title inside the note?
i try to call detail.notes.note.title it say is null or is not a object
this is json data:
{
"infos": {
"info": [
{
"startYear": "1900",
"endYear": "1930",
"timeZoneDesc": "daweerrewereopreproewropewredfkfdufssfsfsfsfrerewrBlahhhhh..",
"timeZoneID": "1",
"note": {
"notes": [
{
"id": "1",
"title": "Mmm"
},
{
"id": "2",
"title": "Wmm"
},
{
"id": "3",
"title": "Smm"
}
]
},
"links": [
{
"id": "1",
"title": "Red House",
"url": "http://infopedia.nl.sg/articles/SIP_611_2004-12-24.html"
},
{
"id": "2",
"title": "Joo Chiat",
"url": "http://www.the-inncrowd.com/joochiat.htm"
},
{
"id": "3",
"title": "Bake",
"url": "https://thelongnwindingroad.wordpress.com/tag/red-house-bakery"
}
]
}
]
}
}
Use http://jsonlint.com/ to help you out with JSON.
I got this...
Parse error on line 30:
... ] }
----------------------^
Expecting '}', ',', ']'