Need to get the desired output for the below input JSON in jolt. I need an output as list of objects instead of nested list. How can I achieve this? Can someone help me with Jolt Spec to achieve the below result?I have mentioned the input json and desired output json below
Input JSON:
{
"Primary Manager" : [ {
"fullName" : "newfnbc ste<script>alert",
"roleName" : "Primary Manager",
"customerGuid" : "2665441603151020"
} ],
"Services Manager" : [ {
"fullName" : "bcp testapr8",
"roleName" : "Services Manager",
"customerGuid" : "779434360108042"
}, {
"fullName" : "bcptest sm8apr16",
"roleName" : "Services Manager",
"customerGuid" : "799910040316042"
}, {
"fullName" : "sample test_sm",
"roleName" : "Services Manager",
"customerGuid" : "2085464009161220"
} ],
"Billing Manager" : [ {
"fullName" : [ "billingmanager01 userbm01", "billingmanager01 userbm01" ],
"roleName" : "Billing Manager, Services User",
"customerGuid" : "1056213702180120, 1056213702180120"
}, {
"fullName" : [ "proddont bm", "proddont bm" ],
"roleName" : "Billing Manager, Services User",
"customerGuid" : "77103112040506, 77103112040506"
} ],
"Services Manager, Billing Manager" : [ {
"fullName" : [ "bcptest smapr23", "bcptest smapr23" ],
"roleName" : "Services Manager, Billing Manager",
"customerGuid" : "882400050623, 882400050623t"
}, {
"fullName" : [ "newpnn proddonot", "newpnn proddonot" ],
"roleName" : "Services Manager, Billing Manager",
"customerGuid" : "167753080429122, 167753080429122"
}, [ {
"fullName" : [ "test smb1102", "test smb1102", "test smb1102" ],
"roleName" : "Services Manager, Billing Manager, Services User",
"customerGuid" : "91625037010, 91625037010, 91625037010"
} ] ],
"Services User" : [ {
"fullName" : "bcp test_su",
"roleName" : "Services User",
"customerGuid" : "3271594409"
} ]
}
desired output:
{
"Primary Manager" : [ {
"fullName" : "newfnbc ste<script>alert",
"roleName" : "Primary Manager",
"customerGuid" : "2665441603151020"
} ],
"Services Manager" : [ {
"fullName" : "bcp testapr8",
"roleName" : "Services Manager",
"customerGuid" : "779434360108042"
}, {
"fullName" : "bcptest sm8apr16",
"roleName" : "Services Manager",
"customerGuid" : "799910040316042"
}, {
"fullName" : "sample test_sm",
"roleName" : "Services Manager",
"customerGuid" : "2085464009161220"
} ],
"Billing Manager" : [ {
"fullName" : [ "billingmanager01 userbm01", "billingmanager01 userbm01" ],
"roleName" : "Billing Manager, Services User",
"customerGuid" : "1056213702180120, 1056213702180120"
}, {
"fullName" : [ "proddont bm", "proddont bm" ],
"roleName" : "Billing Manager, Services User",
"customerGuid" : "77103112040506, 77103112040506"
} ],
"Services Manager, Billing Manager" : [ {
"fullName" : [ "bcptest smapr23", "bcptest smapr23" ],
"roleName" : "Services Manager, Billing Manager",
"customerGuid" : "882400050623, 882400050623t"
}, {
"fullName" : [ "newpnn proddonot", "newpnn proddonot" ],
"roleName" : "Services Manager, Billing Manager",
"customerGuid" : "167753080429122, 167753080429122"
},{
"fullName" : [ "test smb1102", "test smb1102", "test smb1102" ],
"roleName" : "Services Manager, Billing Manager, Services User",
"customerGuid" : "91625037010, 91625037010, 91625037010"
} ],
"Services User" : [ {
"fullName" : "bcp test_su",
"roleName" : "Services User",
"customerGuid" : "3271594409"
} ]
}
Related
I have the following two collections
1)template_data
2)static_data
template_data
{
"_id" : "e1a0a44a-abc1-4185-aefc-2194597a62a2",
"templateName" : "IB Tradebook",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "BUY/SELL",
"attributeValue" : "B"
},
{
"attributeName" : "EXCHANGE ID",
"attributeValue" : "NYBT"
},
{
"attributeName" : "ACCOUNT NUMBER",
"attributeValue" : "XXXXXXX"
},
{
"attributeName" : "BTML NAME",
"attributeValue" : "CCCCCCCCCCCCCCCCCCCCCC"
},
{
"attributeName" : "TRADE SUMMARY ID",
"attributeValue" : "AAA-BBBB-CCCC"
},
{
"attributeName" : "TRADER NAME",
"attributeValue" : "TOM"
}]
},
{
"_id" : "e1a0a44a-abc1-4185-aefc-2194597a62a2",
"templateName" : "CB Tradebook",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "BUY/SELL",
"attributeValue" : "B"
},
{
"attributeName" : "EXCHANGE ID",
"attributeValue" : "NYBT"
},
{
"attributeName" : "ACCOUNT NUMBER",
"attributeValue" : "XXXXXXX"
},
{
"attributeName" : "BTML NAME",
"attributeValue" : "CCCCCCCCCCCCCCCCCCCCCC"
},
{
"attributeName" : "TRADE SUMMARY ID",
"attributeValue" : "AAA-BBBB-CCCC"
},
{
"attributeName" : "TRADER NAME",
"attributeValue" : "TOM"
}]
}
static_data
{
"_id" : "ce62f96f-5ef5-4bb0-8bab-9b0a743f968c",
"templateName" : "User_Inventory",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "TRADING SYSTEM",
"attributeValue" : "ZZZZ",
},
{
"attributeName" : "CLIENT NAME",
"attributeValue" : "XXX TRADING COMPANY",
},
{
"attributeName" : "EFLOW USER ID",
"attributeValue" : "",
},
{
"attributeName" : "TRADER EMAIL ID",
"attributeValue" : "xxxx#goole.com",
},
{
"attributeName" : "USER ID",
"attributeValue" : "TOM"
}]
},
{
"_id" : "ce62f96f-5ef5-4bb0-8bab-9b0a743f968c",
"templateName" : "Client_Inventory",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "TRADING SYSTEM",
"attributeValue" : "ZZZZ",
},
{
"attributeName" : "CLIENT NAME",
"attributeValue" : "XXX TRADING COMPANY",
},
{
"attributeName" : "EFLOW USER ID",
"attributeValue" : "",
},
{
"attributeName" : "TRADER EMAIL ID",
"attributeValue" : "xxxx#goole.com",
},
{
"attributeName" : "USER ID",
"attributeValue" : "TOM"
}]
}
My requirement is
1.From template_data collection i have filter all the documents with
templateName = 'IB Tradebook',
period = 'Jul-2020'
2.From statci_data collection i have filter all the documents with
templateName = 'User_Inventory',
period = 'Jul-2020'
3.filter condition from both collections
template_data.attributeData.attributeName = "TRADER NAME"
static_data.attributeData.attributeName = "USER ID"
SQL Equivalent:
Select template_data.attributeData.attributeName, template_data.attributeData.attributeValue,
static_data.attributeData.attributeName, static_data.attributeData.attributeValue
from template_data
left join static_data on (template_data.attributeData.attributeValue = static_data.attributeData.attributeValue)
Where template_data.attributeData.attributeName in ("BUY/SELL", "EXCHANGE ID", "TRADER NAME")
and static_data.attributeData.attributeName in ("TRADING SYSTEM","CLIENT NAME", "USER ID")
and template_data.templateName = 'IB Tradebook' and template_data.period = 'Jul-2020'
and static_data.templateName = 'User_Inventory' and static_data.period = 'Jul-2020';
db.template_data.aggregate([
{
$lookup :
{ from : "static_data",
localField: "template_data.attributeData.atributeValue"
ForeignField : "static_data.attributeData.atributeValue"
as : "static_details"
}
}
4.$project and expected results
for the above condition the
"template_data.attributeData.atributeValue" (TOM) matches with
"static_data.attributeData.atributeValue" (TOM)
AttributNames to be considered in output
template_data : attributeName["BUY/SELL", "EXCHANGE ID", "TRADER NAME"]
static_data : attributeName["TRADING SYSTEM","CLIENT NAME", "USER ID" ]
output :
{
"_id" : "e1a0a44a-abc1-4185-aefc-2194597a62a2",
"templateName" : "IB Tradebook",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "BUY/SELL",
"attributeValue" : "B"
},
{
"attributeName" : "EXCHANGE ID",
"attributeValue" : "NYBT"
},
{
"attributeName" : "TRADER NAME",
"attributeValue" : "TOM"
}
],
static_details : {
"_id" : "ce62f96f-5ef5-4bb0-8bab-9b0a743f968c",
"templateName" : "User_Inventory",
"period" : "Jul-2020",
"attributeData" : [
{
"attributeName" : "TRADING SYSTEM",
"attributeValue" : "ZZZZ",
},
{
"attributeName" : "CLIENT NAME",
"attributeValue" : "XXX TRADING COMPANY",
},
{
"attributeName" : "USER ID",
"attributeValue" : "TOM"
}]
}
}
I have a fairly simple cloudformation template. I am trying to learn about them. I created one where I am trying to create 2 dyanmo table when I deploy the stack. But only one table gets created. Not two. I am not sure what is wrong with my syntax. Pasting the json below
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"resource1" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_1"
}
}
},
"Resources" : {
"resource2" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_2"
}
}
},
}
There are few mistakes in the template. One already pointed out by #MariaInesParnisari.
The other ones are missing open bracket and unneeded brackets in the middle.
I fixed the template and can confirm it works:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"resource1" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_1"
}
},
"resource2" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_2"
}
}
}
}
More generally, the CloudFormation Linter can help catch these template issues faster with errors like:
E0000 Duplicate found "Resources" (line 35)
I'm trying to work out how to query a document which has two layers of nested arrays.
{
"_id" : ObjectId("5d7fb679d76f3bbf82ed952e"),
"org-name" : "Shropshire Community Health NHS Trust",
"domain" : "shropscommunityhealth.nhs.uk",
"subdomains" : [
{
"name" : "www.shropscommunityhealth.nhs.uk",
"firstSeen" : "2015-10-17 01:10:00",
"a_rr" : "195.49.146.9",
"data_retrieved" : ISODate("2019-09-16T17:21:11.468Z"),
"asn" : 21472,
"asn_org" : "ServerHouse Ltd",
"city" : "Portsmouth",
"country" : "United Kingdom",
"shodan" : {
"ports" : [
{
"port" : 443,
"cpe" : "cpe:/a:microsoft:internet_information_server:8.5",
"product" : "Microsoft IIS httpd"
},
{
"port" : 80,
"cpe" : "cpe:/o:microsoft:windows",
"product" : "Microsoft HTTPAPI httpd"
}
],
"timestamp" : ISODate("2019-09-16T17:21:12.659Z")
}
},
{
"name" : "www2.shropscommunityhealth.nhs.uk",
"firstSeen" : "2017-06-23 16:55:00",
"a_rr" : "80.175.25.17",
"data_retrieved" : ISODate("2019-09-16T17:21:12.663Z"),
"asn" : 8607,
"asn_org" : "Timico Limited",
"city" : null,
"country" : "United Kingdom",
"shodan" : {
"timestamp" : ISODate("2019-09-16T17:21:13.664Z")
}
}
]
}
I want to be able to search through the collection and return all of the subdomains where where there is a match on the port number supplied. So far I've tried (in PyMongo)
result = db.aggregate([{'$match': {'subdomains.shodan.ports.port': port}},
{'$project': {
'subdomains': {'$filter': {
'input': '$subdomains.shodan.ports',
'cond': {'$eq': ['$$this.port', port]}
}}
}}])
When I run this I don't get any results back at all. I've played around with my $filter but can't seem to get any results out. I'm using a similar aggregation for querying within just the subdomains array and it works fine, I'm just struggling with the array within an array and wondering if I need a different approach.
Try aggregate pipeline below:
db.collection.aggregate([
{
$unwind: "$subdomains"
},
{
$match: {
"subdomains.shodan.ports": {
$elemMatch: {
port: 443
},
$ne: null
}
}
},
{
$group: {
_id: "$_id",
"org-name": {
$last: "$org-name"
},
"domain": {
$last: "$domain"
},
"subdomains": {
$push: "$subdomains"
}
}
}
])
giving output:
[
{
"_id": ObjectId("5d7fb679d76f3bbf82ed952e"),
"domain": "shropscommunityhealth.nhs.uk",
"org-name": "Shropshire Community Health NHS Trust",
"subdomains": [
{
"a_rr": "195.49.146.9",
"asn": 21472,
"asn_org": "ServerHouse Ltd",
"city": "Portsmouth",
"country": "United Kingdom",
"data_retrieved": ISODate("2019-09-16T17:21:11.468Z"),
"firstSeen": "2015-10-17 01:10:00",
"name": "www.shropscommunityhealth.nhs.uk",
"shodan": {
"ports": [
{
"cpe": "cpe:/a:microsoft:internet_information_server:8.5",
"port": 443,
"product": "Microsoft IIS httpd"
},
{
"cpe": "cpe:/o:microsoft:windows",
"port": 80,
"product": "Microsoft HTTPAPI httpd"
}
],
"timestamp": ISODate("2019-09-16T17:21:12.659Z")
}
}
]
}
]
The following query can get us the expected output:
db.collection.aggregate([
{
$project:{
"subdomains":{
$filter:{
"input":"$subdomains",
"as":"subdomain",
"cond":{
$in:[
443,
{
$ifNull:[
"$$subdomain.shodan.ports.port",
[]
]
}
]
}
}
}
}
}
]).pretty()
Data set:
{
"_id" : ObjectId("5d7fb679d76f3bbf82ed952e"),
"org-name" : "Shropshire Community Health NHS Trust",
"domain" : "shropscommunityhealth.nhs.uk",
"subdomains" : [
{
"name" : "www.shropscommunityhealth.nhs.uk",
"firstSeen" : "2015-10-17 01:10:00",
"a_rr" : "195.49.146.9",
"data_retrieved" : ISODate("2019-09-16T17:21:11.468Z"),
"asn" : 21472,
"asn_org" : "ServerHouse Ltd",
"city" : "Portsmouth",
"country" : "United Kingdom",
"shodan" : {
"ports" : [
{
"port" : 443,
"cpe" : "cpe:/a:microsoft:internet_information_server:8.5",
"product" : "Microsoft IIS httpd"
},
{
"port" : 80,
"cpe" : "cpe:/o:microsoft:windows",
"product" : "Microsoft HTTPAPI httpd"
}
],
"timestamp" : ISODate("2019-09-16T17:21:12.659Z")
}
},
{
"name" : "www2.shropscommunityhealth.nhs.uk",
"firstSeen" : "2017-06-23 16:55:00",
"a_rr" : "80.175.25.17",
"data_retrieved" : ISODate("2019-09-16T17:21:12.663Z"),
"asn" : 8607,
"asn_org" : "Timico Limited",
"city" : null,
"country" : "United Kingdom",
"shodan" : {
"timestamp" : ISODate("2019-09-16T17:21:13.664Z")
}
}
]
}
Output:
{
"_id" : ObjectId("5d7fb679d76f3bbf82ed952e"),
"org-name" : "Shropshire Community Health NHS Trust",
"domain" : "shropscommunityhealth.nhs.uk",
"subdomains" : [
{
"name" : "www.shropscommunityhealth.nhs.uk",
"firstSeen" : "2015-10-17 01:10:00",
"a_rr" : "195.49.146.9",
"data_retrieved" : ISODate("2019-09-16T17:21:11.468Z"),
"asn" : 21472,
"asn_org" : "ServerHouse Ltd",
"city" : "Portsmouth",
"country" : "United Kingdom",
"shodan" : {
"ports" : [
{
"port" : 443,
"cpe" : "cpe:/a:microsoft:internet_information_server:8.5",
"product" : "Microsoft IIS httpd"
},
{
"port" : 80,
"cpe" : "cpe:/o:microsoft:windows",
"product" : "Microsoft HTTPAPI httpd"
}
],
"timestamp" : ISODate("2019-09-16T17:21:12.659Z")
}
}
]
}
I have below documents in the collection.
{
"_id" : ObjectId("5c98760c27b9fb1266f996b3"),
"user_id" : ObjectId("5c8109785b9a5427b167542a"),
"permissions" : [
{
"dashboard" : [
"Pie Chart",
"Bar Chart"
],
"product management" : [
"update",
"delete",
"list",
"insert"
],
"app user listing" : [
"insert",
"update",
"delete",
"list"
]
}
]
}
I am trying to perform below query:
db.user_permissions.update(
{ user_id: ObjectId("5c8740860c5dcf6c615c1ba3") },
{
"permissions.app user listing": ['inserts']
}
)
what I want to do is to update the value of "app user listing".
Any help appreciated.
EDIT:
This is what I want
Expected Outpupt:
{
"_id" : ObjectId("5c98760c27b9fb1266f996b3"),
"user_id" : ObjectId("5c8109785b9a5427b167542a"),
"permissions" : [
{
"dashboard" : [
"Pie Chart",
"Bar Chart"
],
"product management" : [
"update",
"delete",
"list",
"insert"
],
"app user listing" : [
"inserts"
]
}
]
}
I want to update value of given key with array.
This works on all versions on mongo, you need second argument for find,
db.myColl.update(
{
"user_id" : ObjectId("5c8109785b9a5427b167542a"),"permissions.app user listing":["insersssts"]
},
{
$set: {
"permissions.$.app user listing":["insertss"]
}
});
Try as below:
db.user_permission.update(
{
"user_id" : ObjectId("5c8109785b9a5427b167542a")
},
{
$set: {
"permissions.$[].app user listing": ['inserts']
}
},
{
upsert:false
}
)
Data before running query :
{
"_id" : ObjectId("5c98760c27b9fb1266f996b3"),
"user_id" : ObjectId("5c8109785b9a5427b167542a"),
"permissions" : [
{
"dashboard" : [
"Pie Chart",
"Bar Chart"
],
"product management" : [
"update",
"delete",
"list",
"insert"
],
"app user listing" : [
"insert",
"update",
"delete",
"list"
]
}
]
}
After running query:
{
"_id" : ObjectId("5c98760c27b9fb1266f996b3"),
"user_id" : ObjectId("5c8109785b9a5427b167542a"),
"permissions" : [
{
"dashboard" : [
"Pie Chart",
"Bar Chart"
],
"product management" : [
"update",
"delete",
"list",
"insert"
],
"app user listing" : [
"inserts"
]
}
]
}
What i am try to achieve is getting more than one size from collection.below query not working as expected.
shown below is collection.
{
"_id" : ObjectId("59e9c029c817c359508b4568"),
"client_id" : "20",
"device_details" : {
"type" : "others",
"name" : "Google Bot",
"os" : null,
"os_version" : null,
"browser" : null,
"browser_version" : null,
"user_agent" : "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"width" : NumberLong("1024"),
"height" : NumberLong("1024"),
"fingerid" : "c714d8f7eb7d216693c0ddd06cfc0940",
"canvasfingerid" : "84f1922a78572180c7f29f938486c1db",
"webglfingerid" : "24700f9f1986800ab4fcc880530dd0ed",
"hardwarefingerid" : "431171c98112e1f0dfb3b40f617111f9",
"platformos" : "Linux x86_64",
"adblock" : "false",
"donot" : "unknown",
"liedlanguage" : "false",
"liedos" : "false",
"liedbrowser" : "false",
"ratio" : NumberLong("1"),
"depth" : NumberLong("24"),
"language" : "en-US",
"liedresolution" : "false",
"timezoneoffset" : "420",
"regularplugin" : "No plugins found",
"localstorage" : "true",
"sessionstorage" : "true",
"touchsupport" : "false",
"canvas" : "Tracked",
"webgl" : "Unknown",
"hardwareconc" : "8",
"referrer" : null,
"referrer_url" : null,
"scrorientation" : "landscape-primary"
},
"ip_list" : [
"66.249.66.146",
"66.249.66.21"
],
"ip_details" : [
{
"ip_address" : "66.249.66.146",
"latitude" : 37.41919999999999,
"longitude" : -122.0574,
"city" : "Mountain View",
"postal_code" : "94043",
"country_code" : "US",
"country_name" : "United States",
"continent_code" : "NA",
"created_date" : ISODate("2017-10-20T14:51:45.176+05:30")
},
{
"ip_address" : "66.249.66.21",
"latitude" : 37.41919999999999,
"longitude" : -122.0574,
"city" : "Mountain View",
"postal_code" : "94043",
"country_code" : "US",
"country_name" : "United States",
"continent_code" : "NA",
"created_date" : ISODate("2017-10-24T08:27:24.385+05:30")
}
],
"urls" : [
{
"host" : {
"time" : ISODate("2017-10-20T14:51:45.197+05:30"),
"url" : "http://www.indianmobileprices.com/index.php/mobile/info/9-APPLE/7062-APPLE-iPhone+7+/dehradun"
}
},
{
"host" : {
"time" : ISODate("2017-10-24T08:27:24.405+05:30"),
"url" : "http://www.indianmobileprices.com/brand/mobiles/10-LENOVO/bhubaneswar"
}
}
],
"created_date" : ISODate("2017-10-24T08:27:24.405+05:30"),
"current_timestamp" : NumberLong("1508491305"),
"traffic" : null,
"traffic_url" : [
{
"url" : "",
"date" : ISODate("2017-10-20T14:51:45.197+05:30")
},
{
"url" : "",
"date" : ISODate("2017-10-24T08:27:24.314+05:30")
},
{
"url" : "",
"date" : ISODate("2017-10-24T08:27:24.578+05:30")
}
],
"returning_user" : NumberLong("1"),
"returninguser" : "yes",
"updated_timestamp" : NumberLong("1508813844"),
"multisession" : NumberLong("2")
},
Here is the query i have used.
db.audience.aggregate([
{"$group":{
"_id":"$ip_details.country_name",
"device_information":{
"$addToSet":{
"ipaddress":"$ip_details.ip_address",
"country_name":"$ip_details.country_name",
"device_name":"$device_details.name",
"device_type":"$device_details.type",
"device_os":"$device_details.os",
"devicen_osversion":"$device_details.os_version"
}
},
"count":{"$sum":1}
}},
{ "$project":{
"device_information":1,
"_id":0,
"countrySize":{ "$size":"$device_information.country_name" },
"desktopSize":{ "$size":'$device_information.device_type' }
}},
{ "$match":{ "countrySize":{"$gt":1} }},
{ "$match":{"desktopSize":{"$device_information.device_type":"desktop"} }}
])
For that i could not get expected result is given below.need to change query for the result.
/* 1 */
{
"countrySize" : NumberInt("4"),
"desktopSize" : NumberInt("2"),
"device_information" : [
{
"country_name" : [
"Singapore"
],
"device_name" : "generic web browser",
"device_os" : "Windows",
"device_type" : "desktop",
"devicen_osversion" : "10",
"ipaddress" : [
"52.220.245.83"
]
},
{
"country_name" : [
"Singapore"
],
"device_name" : "Apple iPhone",
"device_os" : "iOS",
"device_type" : "others",
"devicen_osversion" : "10.3.3",
"ipaddress" : [
"185.89.218.227"
]
},
{
"country_name" : [
"Singapore"
],
"device_name" : "generic web browser",
"device_os" : "Mac OS X",
"device_type" : "desktop",
"devicen_osversion" : "10.12.6",
"ipaddress" : [
"121.7.242.239"
]
},
{
"country_name" : [
"Singapore"
],
"device_name" : "Samsung Galaxy Note 4",
"device_os" : "Android",
"device_type" : "mobile",
"devicen_osversion" : "6.0.1",
"ipaddress" : [
"220.255.108.72"
]
}
]
},
I need query for results that is given above.