MONGODB updateOne() query issue - json

This is for upateOne() query in mongodb..
According to me there are not any mistakes in the down given code but the error pops up saying:
" missing } after property list :"
The braces are fully intact, the colons are on and the commas are provided correctly..
Please if anyone could help me with this issue??
db.movieDetails.updateOne(
{
"title":"The Martian"
},
{
$push : {
"reviews":{
$each : [
{
"rating" : 0.5,
"date" : ISODate("2016-01-12T07:00:00Z"),
"reviewer" : "Yabo A.",
"text" : "reviewText2"
},
{
"rating" : 5,
"date" : ISODate("2016-01-12T09:00:00Z"),
"reviewer" : "Kristina Z.",
"text" : "reviewText3"
},
{
"rating" : 2.5,
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Matthew Samuel",
"text" : "reviewText4"
},
{
"rating" : 9.5,
"date" : ISODate("2015-11-23T04:00:00Z"),
"reviewer" : "Mahendra Singh Dhoni",
"text" : "reviewText5"
},
{
"rating" : 7.5,
"date" : ISODate("2016-12-27T09:00:00Z"),
"reviewer" : "Himesh Reshamiya",
"text" : "reviewText6"
},
{
"rating" : 8
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Latish Malinga",
"text" : "reviewText7"
}
]
}
}
}
)

In the last document here you are missing a comma:
{
"rating" : 8
"date" : ISODate("2015-10-26T04:00:00Z"),
"reviewer" : "Latish Malinga",
"text" : "reviewText7"
}
Adding a comma after 8 will fix it.

Related

Jmeter: Extracting JSON response with special/spaces characters

Hello can someone help me extract the value of user parameter which is "testuser1"
I tried to use this JSON Path expression $..data I was able to extract the entire response but unable to extract user parameter. Thanks in advance
{
"data": "{ "took" : 13, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10", "_type" : "network", "_id" : "6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000", "_score" : 1.0, "_source" : { "misMatches" : [ "protocol", "state", "command" ], "instance" : "e3032804-4b6d-3735-ac22-c827950395b4|0.0.0.0|10.179.155.155|53|UDP", "protocol" : "UDP", "localAddress" : "0.0.0.0", "localPort" : "12345", "foreignAddress" : "10.179.155.155", "foreignPort" : "53", "command" : "ping yahoo.com ", "user" : "testuser1", "pid" : "10060", "state" : "OUTGOINGFQ", "rate" : 216.0, "originalLocalAddress" : "192.168.100.229", "exe" : "/bin/ping", "md5" : "f9ad63ce8592af407a7be43b7d5de075", "dir" : "", "agentId" : "abcd-dcd123", "year" : "2021", "month" : "APRIL", "day" : "10", "hour" : "12", "time" : "1618059082000", "isMerged" : false, "timestamp" : "Apr 10, 2021 12:51:22 PM", "metricKey" : "6e2e58be-0ccf-3fb4-8239-1d4f2af322e2", "isCompliant" : false }, "sort" : [ 1618059082000 ] } ] }, "aggregations" : { "count_over_time" : { "buckets" : [ { "key_as_string" : "2021-04-10T08:00:00.000-0400", "key" : 1618056000000, "doc_count" : 1 } ] } }}",
"success": true,
"message": {
"code": "S",
"message": "Get Eval results Count Success"
}
}
Actual Response:
Images
What you posted doesn't look like a valid JSON to me.
If in reality you're getting what's in your image, to wit:
{
"data": "{ \"took\" : 13, \"timed_out\" : false, \"_shards\" : { \"total\" : 5, \"successful\" : 5, \"skipped\" : 0, \"failed\" : 0 }, \"hits\" : { \"total\" : 1, \"max_score\" : 1.0, \"hits\" : [ { \"_index\" : \"bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10\", \"_type\" : \"network\", \"_id\" : \"6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000\", \"_score\" : 1.0, \"_source\" : { \"misMatches\" : [ \"protocol\", \"state\", \"command\" ], \"instance\" : \"e3032804-4b6d-3735-ac22-c827950395b4|0.0.0.0|10.179.155.155|53|UDP\", \"protocol\" : \"UDP\", \"localAddress\" : \"0.0.0.0\", \"localPort\" : \"12345\", \"foreignAddress\" : \"10.179.155.155\", \"foreignPort\" : \"53\", \"command\" : \"pingyahoo.com\", \"user\" : \"testuser1\", \"pid\" : \"10060\", \"state\" : \"OUTGOINGFQ\", \"rate\" : 216.0, \"originalLocalAddress\" : \"192.168.100.229\", \"exe\" : \"/bin/ping\", \"md5\" : \"f9ad63ce8592af407a7be43b7d5de075\", \"dir\" : \"\", \"agentId\" : \"abcd-dcd123\", \"year\" : \"2021\", \"month\" : \"APRIL\", \"day\" : \"10\", \"hour\" : \"12\", \"time\" : \"1618059082000\", \"isMerged\" : false, \"timestamp\" : \"Apr10, 202112: 51: 22PM\", \"metricKey\" : \"6e2e58be-0ccf-3fb4-8239-1d4f2af322e2\", \"isCompliant\" : false }, \"sort\" : [ 1618059082000 ] } ] }, \"aggregations\" : { \"count_over_time\" : { \"buckets\" : [ { \"key_as_string\" : \"2021-04-10T08: 00: 00.000-0400\", \"key\" : 1618056000000, \"doc_count\" : 1 } ] } }}",
"success": true,
"message": {
"code": "S",
"message": "Get Eval results Count Success"
}
}
the easiest way is just using 2 JSON Extractors:
Extract data attribute value into a JMeter Variable from the response
Extract user attribute value into a JMeter variable from ${data} JMeter Variable:
Demo:
If the response looks like exactly you posted you won't be able to use JSON Extractors and will have to treat it as normal text so your choice is limited to Regular Expression Extractor, example regular expression:
"user"\s*:\s*"(\w+)"
Add Regular Expression extractor with the corresponding request and extract it. Use the below expression.
Expression: "user" : "(.*?)"
Ref: https://jmeter.apache.org/usermanual/regular_expressions.html
Regular Expression Extractor Sample

Firebase API REST cant filter data using orderBy [duplicate]

This question already has answers here:
How to perform sql "LIKE" operation on firebase?
(5 answers)
Closed 4 years ago.
i'm trying to filter the data that i have in a database in firebase.
I have a very simple structure of data like this.
{
"articulos" : {
"-LHYw-qz8fiTSg03TuYS" : {
"descripcion" : "refgre",
"fabricante" : "gerg",
"iva" : "21%",
"margen" : "23",
"nombre" : "greerfg",
"preciocompra" : "3213",
"preciocompraiva" : "12312",
"precioventa" : "323",
"precioventaiva" : "23",
"ref" : "4greg"
},
"-LHYwfIIoN46cjlF3VTR" : {
"descripcion" : "gdfgdfg",
"fabricante" : "dfgdf",
"iva" : "21%",
"margen" : "45",
"nombre" : "gfdgdf",
"preciocompra" : "4345",
"preciocompraiva" : "543",
"precioventa" : "543",
"precioventaiva" : "45",
"ref" : "43g34g"
},
"-LHYwvK6xAQeXHQVrmtt" : {
"descripcion" : "fdsf",
"fabricante" : "fdsf",
"iva" : "21%",
"margen" : "34",
"nombre" : "dfsfsd",
"preciocompra" : "sdfsd",
"preciocompraiva" : "dfsd",
"precioventa" : "43",
"precioventaiva" : "34",
"ref" : "432"
}
},
"clientes" : {
"-LHjGlhQD4iP9DOsGgvx" : {
"ciudad" : "rtbrtbrt",
"comentarios" : "gfdgfd",
"correo" : "brt#hotmail.com",
"cp" : "43243",
"direccion" : "tbrb",
"dni" : "rtbrtb",
"id" : 2,
"nombre" : "5brtbtrb"
},
"-LHjHImLC3UBW3M2Rf3_" : {
"ciudad" : "fmdkjsf",
"comentarios" : ".comsfdasa",
"correo" : "dkfmsldfm#jnfdjsn",
"cp" : "32434",
"direccion" : "fkdmfkjsd",
"dni" : "mklrmg",
"id" : 2,
"nombre" : "gkjsdnfgd"
}
}
}
i have been reading the documentation, and i have read about indexOn.
Currently i have this rules.
{
"rules": {
".read": true,
".write": true,
"clientes": {
".indexOn": ["nombre"]
}
}
}
I'm not sure if i'm doing it well.. but when i send de URL,
/clientes.json?orderBy="nombre"&startAt=x
it is retrieving all the "clientes" that i have in the DataBase...
How i supposed to do it for receive all the "clientes" that start at "x"... i'm trying to develop a search input in my website...
When I add your JSON to my database, it works as expected:
https://stackoverflow.firebaseio.com/51471121/clientes.json?orderBy="nombre"&startAt="x"
Gives me no results, because there is no name starting with x or later.
But:
https://stackoverflow.firebaseio.com/51471121/clientes.json?orderBy="nombre"&startAt="f"
Gives me one result, since "nombre" : "gkjsdnfgd" is after f.

Mongo forEach Query

I have the JSON that you can see below and I want to sum the values of the two objects, but when I make an aggregation it returns me 0.Here you can see the query that I use; really the first line I only use it to be sure that the path works, and it does. On the other hand,when I use this path in the aggregation query it gives me the "ID" and the "COUNT" with right values,but the "SUM" is always 0 when it must be 3600.Any idea?
db.getCollection('TEST').find({"prices.year.months.day.csv.price.valPrice":1800})
db.TEST.aggregate([
{ $match: {"location.cp":"20830"}},
{$group:{_id:"20830",total:{$sum:"$prices.year.months.day.csv.price.valPrice"}, count: { $sum: 1 }
}}])
And this is the JSON:
{
"_id" : "20830:cas:S:3639",
"lodgtype" : "Casa",
"lodg" : "Motrico: country holiday home - San sebastian",
"webid" : "6107939",
"location" : {
"thcod" : "20",
"cp" : "20830",
"th" : "Gipuzkoa",
"geometry" : {
"type" : "Point",
"coordinates" : [
43.31706238,
-2.40293598
]
}
},
"prices" : {
"year" : [
{
"valYear" : "2018",
"months" : [
{
"valMonth" : "02",
"day" : [
{
"valDay" : "13",
"csv" : [
{
"valCsv" : "20180205210908_223",
"price" : [
{
"valPrice" : 1800.0
}
]
}
]
}
]
}
]
}
]
},
"reg" : {
"created" : "20180213",
"updated" : "20180213",
"viewed" : "20180213"
}
},{
"_id" : "TEST20830:cas:S:3639",
"lodgtype" : "Casa",
"lodg" : "TESTMotrico: country holiday home - San sebastian",
"webid" : "6107930",
"location" : {
"thcod" : "20",
"cp" : "20830",
"th" : "Gipuzkoa",
"geometry" : {
"type" : "Point",
"coordinates" : [
43.31706238,
-2.40293598
]
}
},
"prices" : {
"year" : [
{
"valYear" : "2018",
"months" : [
{
"valMonth" : "02",
"day" : [
{
"valDay" : "13",
"csv" : [
{
"valCsv" : "20180205210908_223",
"price" : [
{
"valPrice" : 1800.0
}
]
}
]
}
]
}
]
}
]
},
"reg" : {
"created" : "20180213",
"updated" : "20180213",
"viewed" : "20180213"
}
}
Since you've deeply nested array you've to unwind to flatten to a document structure. To count the number of matches you've to use extra group after $match with $push with $$ROOT to keep the matching data.
db.TEST.aggregate([
{"$match":{"location.cp":"20830"}},
{"$group":{
"_id":"20830",
"data":{"$push":"$$ROOT"},
"count":{"$sum":1}
}},
{"$unwind":"$data.prices.year"},
{"$unwind":"$data.prices.year"},
{"$unwind":"$data.prices.year.months"},
{"$unwind":"$data.prices.year.months.day"},
{"$unwind":"$data.prices.year.months.day.csv"},
{"$unwind":"$data.prices.year.months.day.csv.price"},
{"$group":{
"_id":"20830",
"total":{"$sum":"$prices.year.months.day.csv.price.valPrice"},
"count":{"$first":"$count"}
}}
])

MongoDB aggregation - group and retrieve ohters fileds

i have a collection with this documents:
{
"_id" : BinData(3,"utMu84VFQk+p6LOEE3Ia3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "MIL",
"City" : "Milano",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 150,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
{
"_id" : BinData(3,"utMu845468+p6Lertya3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "AOI",
"City" : "Ancona",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 100,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
.........
.........
I want to group by ONLY Destination.City and return an object with
Destination.City, Destination.Code and count. Like this example:
/* 1 */
{
"_id" : {
"Code" : "PMO",
"City" : "Palermo",
"Country" : "IT"
},
"count" : 184564.0
},
/* 2 */
{
"_id" : {
"Code" : "CAG",
"City" : "Cagliari",
"Country" : "IT"
},
"count" : 130873.0
},
......
......
I tried with this query (i use MongoBooster):
db.parsed_data.aggregate([
{ "$match" : { "Destination.Country" : "IT", "Segments" : { "$elemMatch" : { "Carrier" : "AZ" } } } },
{ "$group" : { "_id" : { "City" : "$Destination.City"}, "count" : { "$sum" : 1 } } },
{ "$project" : {"Destination.Code" : 1, "Destination.City" : 1, "Destination.Country" : 1 }},
{ "$sort" : { "count" : -1 } },
{ "$limit" : 9 }])
It returns grouped by City but it shows only the City Name.
In this way:
/* 1 */
{
"_id" : {
"City" : "Lampedusa"
}
},
/* 2 */
{
"_id" : {
"City" : "Trieste"
}
},
This is not correct.
How can i group by ONLY the Destination.City and return an object with
Destination.City, Destination.Code and count?
Thx

JsonPath - Extract property by name

I am trying to extract any property name containing "cpu" and "usageRatio" from the following Json using Jayway JsonPath, but so far I have been out of luck.
Checked their documentation and could not find a solution. Any ideas?
To be clear, I would like to extract cpu usage ration for all cpu's in a dynamict fashion (there can be many cores):
{
"entries" : {
"cpu.0_1.user" : {
"lastUpdateMicros" : 1493578024979676,
"value" : 10167446,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.idle" : {
"value" : 277255191,
"lastUpdateMicros" : 1493578024979652,
"updateType" : "MOVING_AVERAGE"
},
"disk.usr.usageRatio" : {
"value" : 0.871294498443604,
"lastUpdateMicros" : 1493578024990246,
"updateType" : "BASIC"
},
"disk.shared.usedSpace" : {
"updateType" : "BASIC",
"lastUpdateMicros" : 1493578024990318,
"value" : 707563520
},
"disk.var.log.availableSpace" : {
"lastUpdateMicros" : 1493578024990355,
"value" : 7224614912,
"updateType" : "BASIC"
},
"disk.usr.local.www.guiserverroot.usr.local.www.guiserver.availableSpace" : {
"value" : 2369658880,
"lastUpdateMicros" : 1493578024990398,
"updateType" : "BASIC"
},
"cpu.0_0.idle" : {
"value" : 265264234,
"lastUpdateMicros" : 1493578024979593,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.usageRatio" : {
"value" : 0.07,
"lastUpdateMicros" : 1493578024979635,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_0.usageRatio" : {
"lastUpdateMicros" : 1493578024979564,
"value" : 0.12,
"updateType" : "MOVING_AVERAGE"
}
}
Yes, I know the Json structure sucks but sadly I don't have access to change it.
/Patrik