The argument to $each in $push must be an array but it was of type Object - mongodb-query

I want to add the element in array but in my document conation one object :_id in that I have another filed xxxxx in that list I want to add
"_id" : ObjectId("5cf261718c81f028sd73b2f9")
"college" : {
"clzName" : "VDA",
"clzList" : [],
"List" : [],
"place" : [],
"date" : [
"college"
]
},
db.getCollection('aaa').update({"_id" : ObjectId("5cf261718c81f028db73b2f9")},
{$push:{"colllege":{$each:{"List":["dsd","jaa"]}}}})
e argument to $each in $push must be an array but it was of type Object

Try this it should work,
db.getCollection('aaa').update({"_id" : ObjectId("5cf261718c81f028db73b2f9")},
{$push:{"colllege":{$each:[["List":["dsd","jaa"]]]}}})
It will insert it like this
"college":{
[
"List":[
"dsd",
"jaa"
]
]
}

Related

Get from jenkins list of nodes by label - by REST API

I need to GET list of nodes that contains certain label.
I know how to do that by getting entire nodes list by using Jenkins REST API and then getting node by node also REST API and checking its labels - but its to many API calls.
I also can create some job that writing to some place nodes list by label as parameter - but its bad way as Jenkins job that triggered remotely have no return value and I cant know it finished and will need read results from some other place the job saved it there.
I need some way that by one API call I will get nodes list contains a given label.
You can run a single API call to <JENKINS_URL>/computer/api/json (or <JENKINS_URL>/computer/api/python for a python api) which return a list of all nodes and their properties.
One of the properties is the label - so just go over all nodes and extract the ones that contain your needed label.
Here is an example for the returned object:
{
"_class" : "hudson.model.ComputerSet",
"busyExecutors" : 0,
"computer" : [
{
"_class" : "hudson.model.Hudson$MasterComputer",
"actions" : [
],
"assignedLabels" : [
{
"name" : "built-in"
}
],
"description" : "the Jenkins controller's built-in node",
"displayName" : "Built-In Node",
"executors" : [
{
},
{
}
],
"icon" : "symbol-computer",
"iconClassName" : "symbol-computer",
"idle" : true,
"jnlpAgent" : false,
"launchSupported" : true,
"loadStatistics" : {
"_class" : "hudson.model.Label$1"
},
"manualLaunchAllowed" : true,
"monitorData" : {
"hudson.node_monitors.SwapSpaceMonitor" : {
"_class" : "hudson.node_monitors.SwapSpaceMonitor$MemoryUsage2",
"availablePhysicalMemory" : 6938730496,
"availableSwapSpace" : 6906019840,
"totalPhysicalMemory" : 16885276672,
"totalSwapSpace" : 21046026240
},
"hudson.node_monitors.TemporarySpaceMonitor" : {
"_class" : "hudson.node_monitors.DiskSpaceMonitorDescriptor$DiskSpace",
"timestamp" : 1653907906021,
"path" : "C:\\Windows\\Temp",
"size" : 426696622080
},
"hudson.node_monitors.DiskSpaceMonitor" : {
"_class" : "hudson.node_monitors.DiskSpaceMonitorDescriptor$DiskSpace",
"timestamp" : 1653907905929,
"path" : "C:\\ProgramData\\Jenkins\\.jenkins",
"size" : 426696622080
},
"hudson.node_monitors.ArchitectureMonitor" : "Windows 10 (amd64)",
"hudson.node_monitors.ResponseTimeMonitor" : {
"_class" : "hudson.node_monitors.ResponseTimeMonitor$Data",
"timestamp" : 1653907905941,
"average" : 0
},
"hudson.node_monitors.ClockMonitor" : {
"_class" : "hudson.util.ClockDifference",
"diff" : 0
}
},
"numExecutors" : 2,
"offline" : false,
"offlineCause" : null,
"offlineCauseReason" : "",
"oneOffExecutors" : [
],
"temporarilyOffline" : false
}
],
"displayName" : "Nodes",
"totalExecutors" : 2
}
You are interested in the assignedLabels object - notice that it can contain multiple labels.

Is it possible to use multiple json_object functions under one json_arrayagg function in Oracle?

I need to create JSON that has two sets of json objects under one array. These objects contain aggregated data from several tables. When I use json_arrayagg I get this error:
ORA-02000: missing ) keyword
The code should help explain more of what I've done and what I need.
SELECT JSON_OBJECT(
'rData' VALUE JSON_ARRAYAGG(
JSON_OBJECT(
'datapoints' VALUE JSON_ARRAY(JSON_OBJECT('key' VALUE 'ENM008137Q00190',
'value' VALUE tab3.column_6)),
'datatype' VALUE 'DATA_TYPE',
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7),
JSON_OBJECT(
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7,
'datatype' VALUE 'DATA_TYPE_2',
'datapoints' VALUE JSON_ARRAYAGG(JSON_OBJECT(
'key' VALUE tab5.column_8,
'value' VALUE tab2.column_9))))RETURNING CLOB)
FROM table_3 tab3,
table_4 tab4,
table_2 tab2,
table_1 tab1,
table_5 tab5
WHERE tab1.column_1 = tab2.column_1
AND tab3.column_2 = tab4.column_2
AND tab3.column_1 = tab2.column_1
AND tab1.column_1 = tab3.column_1
AND tab2.column_3 = tab5.column_3
AND tab2.latenttypeid = 1
AND tab3.column_2 = 2952326910
AND tab2.column_10 = 8878887
AND tab3.column_10 = 8878887
AND tab1.date BETWEEN '19-jun-19'
AND '25-jun-19'
GROUP BY tab1.column_4, tab3.column_1, tab3.column_6, tab1.column_7;
And here is the json output I would like:
{
"rData": [{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "10"}
],
"datatype": "DATA_TYPE",
"id": "H2hnJikUKAhGVzslBVBHqg86DnwGhh8V",
"key": "534421188",
"timestamp": "2019-07-05T05:33:12.000Z"
},
{
"key":"534421188",
"id":"H2hnJikUKAhGVzslBVBHqg86DnwGhh8V" ,
"timestamp": "2019-07-05T05:33:12.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "56.0869029"},
{"key" : "ENM008137L0002","value" : "59.79244788"},
{"key" : "ENM008137L0003","value" : "73.34481183"},
{"key" : "ENM008137L0004","value" : "43.94661396"},
{"key" : "ENM008137L0005","value" : "80.71909567"},
{"key" : "ENM008137L0006","value" : "97.2707082"}
]
},{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "9"}
],
"datatype": "DATA_TYPE",
"id": "A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj",
"key": "534421164",
"timestamp": "2019-07-05T04:27:45.000Z"
},
{
"key":"534421164",
"id":"A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj" ,
"timestamp": "2019-07-05T04:27:45.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "88.0869029"},
{"key" : "ENM008137L0002","value" : "88.79244788"},
{"key" : "ENM008137L0003","value" : "88.34481183"},
{"key" : "ENM008137L0004","value" : "82.94661396"},
{"key" : "ENM008137L0005","value" : "99.71909567"},
{"key" : "ENM008137L0006","value" : "88.2707082"}
]
}]
}
There are 2 json_objects under the "rData" array, these are the two data sources that I wanted aggregated, but I'm not sure if that's possible with the current functions.
I apologize for the code, I've tried to give you the least amount of info needed to help with this. And of course any help is always appreciated.

How to look for more than one element in an embedded array in MongoDb

I have a mongodb query: (Give me settings where account='test')
db.collection_name.find({"account" : "test1"}, {settings : 1}).pretty();
where I get the following output:
{
"_id" : ObjectId("49830ede4bz08bc0b495f123"),
"settings" : {
"clusterData" : {
"us-south-1" : "cluster1",
"us-east-1" : "cluster2"
},
},
What I'm looking for now, is to give me the account where the clusterData has more than 1 element in its array.
I'm only interested in listing those accounts with (2) or more elements.
I've tried this:
db.collection_name.find({'settings.clusterData.1': {$exists: true}}, {account : 1}).pretty();
Its not returning any results. Is my query correct? Is there another way to do this?
The reason that it isn't working is that your clusterdata is an object, not an array. I would suggest changing your data to be an array of clusters with two properties like below, then it will work.
{
"_id" : ObjectId("49830ede4bz08bc0b495f123"),
"settings" : {
"clusterData" : [
{
name : "cluster1",
location : "us-south-1"
},
{
name : "cluster2",
location : "us-east-1"
}
]
}
}

access Object/Key-value pair from dictionary

I have the following dictionary
{
"b3e0aded-d57b-4159-9c33-c8b006282334" : {
"57646099-b717-4a2b-b9eb-2935548ae954" : [
"yes"
]
},
"1b186bc7-52c4-4b87-a97f-cc52054aad24" : {
"aba16653-bda0-4e89-b1c8-63df6faa7c10" : [
"yes"
]
},
"d765038e-e85a-495d-9932-170852fbd86e" : {
"aba16653-bda0-4e89-b1c8-63df6faa7c10" : [
"yes"
],
"57646099-b717-4a2b-b9eb-2935548ae954" : [
"yes"
],
"957bdaba-b23d-4243-8384-62dfa46f0656" : "play"
},
"2a8dd370-2f7e-4c8e-93d5-21102fbc82fd" : {
"aba16653-bda0-4e89-b1c8-63df6faa7c10" : [
"yes"
]
}
}
How to get each object say
"b3e0aded-d57b-4159-9c33-c8b006282334" : {
"57646099-b717-4a2b-b9eb-2935548ae954" : [
"yes"
]
}
OR
"d765038e-e85a-495d-9932-170852fbd86e" : {
"aba16653-bda0-4e89-b1c8-63df6faa7c10" : [
"yes"
],
"57646099-b717-4a2b-b9eb-2935548ae954" : [
"yes"
]
from this NSDictionary?
use for each in loop to get the full value. i.e
let dict = your dictionary
for each in dict {
print(each)
}
You can use objectForKey: to read the value for a key:
id value = [dict objectForKey:#"b3e0aded-d57b-4159-9c33-c8b006282334"]
Which can be expressed more concisely using square bracket notation:
id value = dict[#"b3e0aded-d57b-4159-9c33-c8b006282334"]
If you then want an object containing just that key mapped to its value then the easiest thing to do is just to construct a new object with the key and value:
id key = #"b3e0aded-d57b-4159-9c33-c8b006282334";
id value = dict[key];
id result = #{ key: value }

Mongodb aggregate with joins with multiple keys statement

Actually i am not trying to match two collection's . I am looking for match the field with secondary collection. I'll explain my problem clearly:
this is my primary collection "bags".which contains
{
"_id" : ObjectId("568f43e08a9f71b70b22a694"),
"bagNo" : "HBBN/00001/16",
"category" : "Voluntary",
"regNo" : "DNR/00001/16",
"status": "Accepted"
},
{ "_id" : ObjectId("568f4645fa0758af0e3fef26"), "bagNo" :"HBBN/00002/16", "category" : "Voluntary", "regNo" : "DNR/00002/16", "status": "Rejected" },
{ "_id" : ObjectId("568f4645fa4546gygfef26"), "bagNo" : "HBBN/00003/16", "category" : "Voluntary", "regNo" : "DNR/00003/16", "status": "Accepted" }
now my join collection "donor" contains
{"donorType" : "H",
"regNo" : "DNR/00001/16",
"surName" : "pandey",
"firstName" : "rakesh"},
{"donorType" : "C", "regNo" : "DNR/00002/16", "surName" : "pandey", "firstName" : "rakesh" },
{"donorType" : "C", "regNo" : "DNR/00003/16", "surName" : "pandey", "firstName" : "rakesh" }
from these two collections i want to get the accepted bags data from bags collection which having 'donortype' as 'H' in donor collection.Please let me know if it is possible.explain with some example
To combine two collections, you could try to do it with $lookup in aggregation.
donor.aggregation([
// filter the `donortype` of `H`
{$match: {donortype: 'H'}},
// join with `bags` collection for the foreign key `regNo`, and put bags into `h_bags` result.
{$lookup: {
from: "bags",
localField: "regNo",
foreignField: "regNo",
as: "h_bags"
}},
// unwind the `h_bags` array
{$unwind: '$h_bags'},
// filter the status of bags is `Accepted`
{$match: {'h_bags.status': 'Accepted'}}
]);