MongoDB slow query over an empty collection that has a watch - mongodb

I'm relatively new in MongoDB.
I have a single MongoDB instance in replica set in order to use 'watch'. We are currently watching on 'insert' events over the 'removeCollection' collection, the point is this collection is always empty (so noone is inserting anything there right now).
But the log is suddenly showing the below "slow query" message dozens of times. When this happens, the cpu consumption increases a 20%.
{
"t":{
"$date":"2022-11-16T09:15:45.836+00:00"
},
"s":"I",
"c":"COMMAND",
"id":51803,
"ctx":"conn522936",
"msg":"Slow query",
"attr":{
"type":"command",
"ns":"ventusproxy1.removeCollection",
"command":{
"getMore":2257121337268066828,
"collection":"removeCollection",
"batchSize":2147483647,
"$db":"ventusproxy1",
"$clusterTime":{
"clusterTime":{
"$timestamp":{
"t":1668590144,
"i":14391
}
},
"signature":{
"hash":{
"$binary":{
"base64":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"subType":"0"
}
},
"keyId":0
}
},
"lsid":{
"id":{
"$uuid":"47ffbf37-2a66-4b6f-bfb0-57f0e83075e2"
}
},
"$readPreference":{
"mode":"primaryPreferred"
}
},
"originatingCommand":{
"aggregate":"removeCollection",
"pipeline":[
{
"$changeStream":{
}
},
{
"$match":{
"operationType":"insert"
}
}
],
"cursor":{
"batchSize":2147483647
},
"$db":"ventusproxy1",
"$clusterTime":{
"clusterTime":{
"$timestamp":{
"t":1668590004,
"i":1046
}
},
"signature":{
"hash":{
"$binary":{
"base64":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"subType":"0"
}
},
"keyId":0
}
},
"lsid":{
"id":{
"$uuid":"47ffbf37-2a66-4b6f-bfb0-57f0e83075e2"
}
},
"$readPreference":{
"mode":"primaryPreferred"
}
},
"planSummary":"COLLSCAN",
"cursorid":2257121337268066828,
"keysExamined":0,
"docsExamined":17228,
"numYields":13243,
"nreturned":0,
"queryHash":"8D9BAD8C",
"reslen":319,
"locks":{
"FeatureCompatibilityVersion":{
"acquireCount":{
"r":13244
}
},
"Global":{
"acquireCount":{
"r":13244
}
},
"Mutex":{
"acquireCount":{
"r":1
}
}
},
"readConcern":{
"level":"majority"
},
"writeConcern":{
"w":"majority",
"wtimeout":0,
"provenance":"implicitDefault"
},
"storage":{
"data":{
"bytesRead":89
}
},
"remote":"10.1.0.7:36266",
"protocol":"op_msg",
"durationMillis":210
}
}
I have searched trying to find a reason for that ... no luck. And I honestly don't know where to start. I would really appreciated if someone could point me to the right direction.
Thanks,
Joan.

Related

Empty cells canvas during migration to chart-js 3x

I am currently migrating our application using an old version of chart-js but at the moment I am a bit lost.
NB : The old project was made with vuejs 2 and now we are using nuxt3 rc11
By reading the documentation on the migration, many things have changed and I have trouble finding my way around:
https://www.chartjs.org/docs/latest/getting-started/v3-migration.html
Here is what the parameters I send to chart-js look like
{
"type":"doughnut",
"data":{
"labels":[
"",
"",
"",
""
],
"datasets":[
{
"data":[
16,
0,
0,
1
],
"backgroundColor":[
"#00CBA1",
"#FFBF00",
"#FF406C",
"#4C49AF"
],
"borderWidth":"transparent"
}
]
},
"plugins":[
],
"options":{
"hover":{
"mode":"index",
"axis":"y"
},
"legend":{
"display":false
},
"scales":{
"x":{
"gridLines":{
"display":false
},
"ticks":{
"padding":10,
"display":false
}
},
"y":{
"ticks":{
"beginAtZero":true,
"padding":20,
"display":false
},
"gridLines":{
"drawBorder":false,
"color":"#E3E3E3",
"zeroLineColor":"#E3E3E3",
"display":false
}
}
},
"tooltip":{
"enabled":false
},
"maintainAspectRatio":true,
"responsive":true,
"tooltips":{
},
"layout":{
"padding":{
"top":10,
"right":10
}
},
"cutoutPercentage":60
}
}
I don't know what is wrong with this actualy because my canvas display empty cells like this
I thank you in advance for your clarification

MongoDB and Flask - Updating objects in a document's array (nested updating)

Assume we have following collection.
{
"Region":"Karnataka",
"ShortCode":"KA",
"SubRegion":[
{
"District":"Banglore",
"Commodity":[
{
"Name":"items",
"isActive":true,
"CommoditySubType":[
{
"Title":"Moistouriser",
"isActive":true,
"hasGrades":true,
"Grade":[
{
"Title":"Premium",
"Rate":"150",
"isActive":true,
"hasRates":true,
"hasSizes":true,
"StartDate":"2021-03-31",
"EndDate":"2021-04-06",
"StartTime":"9:00am",
"EndTime":"6:00pm",
"Sizes":[
{
"Title":"Small",
"isActive":true
}
]
"LastSevenDaysDates":[{
"Date":2021-03-31,
"Price":"150"
}]
}
]
}
]
}
]
},
{
"District":"Coorg",
"Commodity":[]
}
] }
I want to update an object under LastsevndayDates. I tried this.
mongo.db.supplierDailyPrice.update(
{
"Region":region,
"SubRegion.District":district,
"SubRegion.Commodity.Name":commodity,
"SubRegion.Commodity.CommoditySubType.Title":commoditysubtype,
"$and": [
{ "SubRegion.Commodity.CommoditySubType.Grade": { "$exists": True}},
{ "SubRegion.Commodity.CommoditySubType.Grade.Title": "Premium" },
]
},
{
"$set": {
"SubRegion.$[].Commodity.$[].CommoditySubType.$[].Grade.$[].LastSevenDaysDates": Date
}
})
But it's failing with the error pymongo.errors.WriteError: The path 'SubRegion.0.Commodity.0.CommoditySubType.1.Grade' must exist in the document in order to apply array updates.
You can use arrayFilters to solve your problem
db.supplierDailyPrice.update({
"Region":region
},
{
$set:{
"Subregion.$[sub].Commodity.$[com].CommoditySubType.$[Cst].Grade.$[grd]. LastSevenDaysDates.$[sev].date": Date
}
},
{
array_filter : [
{"sub.district": district},
{"com.name": commodity},
{"Cst.title": commoditysubtype},
{"grd.title": "premium"},
{"sev.price":"150"},
]
})
Not tested the code but something like this will solve your problem. For more reference you can check out the links below:
Update deeply nested array in mongodb
update deeply nested array mongodb
Pymongo error for ArrayFilters to update multiple subdocuments
Ujjwal's answer is on the right track. I fixed a few typos.
More information here about $[] usage.
https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/
https://developer.mongodb.com/how-to/update-array-elements-document-mql-positional-operators/
db.supplierDailyPrice.update_one({
"Region": region
},
{
$set:{
"SubRegion.$[sub].Commodity.$[com].CommoditySubType.$[cst].Grade.$[grd].LastSevenDaysDates.$[sev].Date": "2021-04-03"
}
},
{
"array_filters" : [
{"sub.District": district},
{"com.Name": commodity},
{"cst.Title": commoditysubtype},
{"grd.Title": grade},
{"sev.Price":"150"},
]
},
{
upsert=true
}
)

update data data in EmbeddedListField as other dict field data MongoEngine

I am trying to update a field under doc_list which in proect_list is an embeddeddocumentfield
using [ mongoengine ]
"_id":{
"$oid":"5efae3a302449b643b2e5a06"
},
"username":"Roshan",
"project_list":[
{
"project_id":"216198",
"customername":"Gopal",
"customer_region":"IND",
"doc_list":{
"status":"Inprogress",
"date_modified":{
"$date":"2020-06-30T12:32:59.851Z"
},
"date_started":{
"$date":"2020-06-30T12:32:59.851Z"
},
"nrfu_doc_id":"",
"reference_doc_id":""
}
},
{
"project_id":"624615",
"customername":"xcisco",
"customer_region":"IND",
"doc_list":{
"status":"Completed",
"date_modified":{
"$date":"2020-06-30T12:35:06.031Z"
},
"date_started":{
"$date":"2020-06-30T12:35:06.031Z"
},
"nrfu_doc_id":"",
"reference_doc_id":""
}
}
]
}
I have tried this and tried lot of other examples in MongoEngine Documentation and also Searched in StackOverflow not yet resolved, Please Help me to do this Update.
users = PersonProjectCollection.objects(username="Roshan", project_list__project_id="216198").update_one(set__project_list__doc_list__S__reference_doc_id='21333')
mongoengine.errors.OperationError: Update failed (Cannot create field 'doc_list' in element {project_list: [ { project_id: "216198", customername: "Gopal",
customer_region: "IND", doc_list: { status: "Inprogress", date_modified: new Date(1593520379851), date_started: new Date(1593520379851), nrfu_doc_id: "",
reference_doc_id: "" } }, { project_id: "624615", customername: "xcisco", customer_region: "IND", doc_list: { status: "Completed", date_modified: new Date(
1593520506031), date_started: new Date(1593520506031), nrfu_doc_id: "", reference_doc_id: "" } } ]})
maybe this approach help you
index = 0
users = PersonProjectCollection._get_collection.update_one(
{
"username":"Roshan",
"project_list.project_id":"216198"
},
{
"$set": {
"project_list.%d.doc_list.reference_doc_id" % index: "21333"
}
}
)

Posting to Consecutive Commands to Solr - Data Missing from 1st Call

I am sending the following commands with
my $url = "http://xxxxx/solr/inventory/update?commitWithin=1000";
I am using perl to send to a solr setup on another server.
Please excuse the formatting. I really did try.
Thanks
Mike
RESULTING DATA - The data from the first command is not here. All subsequent calls are.
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"fq":"id:3-159682",
"_":"1529984183431"
}
},
"response":{
"numFound":1,
"start":0,
"docs":[
{
"checklist_id":249746,
"brand_s":"Pinnacle",
"featured":"",
"sf_set_sort":"Baseball1992Pinnacle",
"sf_set_sort_s":"Baseball1992Pinnacle",
"sport_s":"Baseball",
"cardnumber":"308",
"issue_s":"",
"id":"3-159682",
"year_s":"1992",
"team":"Los Angeles Dodgers",
"set_name_s":"",
"has_image":1,
"amazon_sku":"159682",
"amazon_sync":1,
"sf_id":378827,
"sf_ending_time":2222222222,
"sf_sort_id":199230875,
"sf_listing_type":"buy",
"shopify_id":"1302493397094",
"_version_":1604345060355211264
}
]
}
}
COMMANDS AND RESPONSES
[
{
"inv_location":"",
"ean":"",
"site_id":"3",
"category_id":[
"1",
"55",
"2162220",
"2715086",
"306",
"2352370",
"2413461"
],
"cp_id":"159682",
"isbn":"",
"id":"3-159682",
"consigner":"",
"upc_code":"0",
"quantity":"1",
"created_date":"2018-06-26T10:17:55Z",
"mpn":"",
"description":"",
"inv_num":"",
"cp_listing_type":"1",
"price":"0.69",
"title":"1992 Pinnacle #308 Darryl Strawberry NM-MT ",
"live_status":""
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
[
{
"checklist_id":"249746",
"brand_s":"Pinnacle",
"featured":"",
"sf_set_sort":"Baseball1992Pinnacle",
"sport_s":"Baseball",
"cardnumber":"308",
"issue_s":"",
"id":"3-159682",
"year_s":"1992",
"team":"Los Angeles Dodgers",
"set_name_s":""
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
[
{
"has_image":{
"set":"1"
},
"id":"3-159682"
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
[
{
"amazon_sku":{
"set":"159682"
},
"amazon_sync":{
"set":"1"
},
"id":"3-159682"
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
[
{
"sf_id":{
"set":"378827"
},
"sf_ending_time":{
"set":"2222222222"
},
"sf_sort_id":{
"set":"199230875"
},
"id":"3-159682",
"sf_listing_type":{
"set":"buy"
}
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
[
{
"id":"3-159682",
"shopify_id":{
"set":"1302493397094"
}
}
]
Success: {
"responseHeader":{
"status":0,
"QTime":1
}
}
The two documents you submit have the same id. The second document overwrites the first one, since the id has to uniquely identify a document. If the id doesn't do that, change which field is defined as a uniqueKey, or use a UUID generator to get a new id each time the document is submitted. The latter will cause issues if you're trying to do updates without having the new uuid readily available, tho.
Another solution would be to prefix the id with the document type, or (depending on your use case) merge it into a single document before indexing.
The answer to my problem was that the 1st and 2nd commands were full updates, and the rest were partial updates (using "set"
I change the second command to a format like this
[{"checklist_id":{"set":"249725"},"brand_s":{"set":"Pinnacle"},"featured":{"set":""},"sf_set_sort":{"set":"Baseball1992Pinnacle"},"sport_s":{"set":"Baseball"},"cardnumber":{"set":"287"},"issue_s":{"set":""},"id":"3-159694","year_s":{"set":"1992"},"team":{"set":"Milwaukee Brewers"},"set_name_s":{"set":""}}]
And all was right with the code, no lionger overwriting the first query.
Maybe this will help someone else!
Thanks
Mike

How do I use the Echonest API Start Parameter?

I am following the examples located on the following page:
http://developer.echonest.com/docs/v4/genre.html#artists
I'd like to offset the results from a search for artists by genre. The example they provide on the page listed "results" and "start". I assume "start" is the offset. The example query they provide is:
http://developer.echonest.com/api/v4/genre/artists?api_key=JEXNQ223JXCCQEINO&format=json&results=5&start=0&bucket=hotttnesss&name=jazz
But I get any error stating the "start" is an invalid parameter. Has anyone been able to use the "start" parameter with success?
This looks like a bug in their example. If you read the documentation, "start" and "results" are not valid for the genre/artists endpoint. Changing the example to remove these to parameters works.
Calling:
http://developer.echonest.com/api/v4/genre/artists?api_key=*********&format=json&bucket=hotttnesss&name=jazz
(replace the *** with your Key)
Yields:
{
"response":{
"status":{
"version":"4.2",
"code":0,
"message":"Success"
},
"artists":[
{
"name":"John Coltrane",
"hotttnesss":0.588225,
"id":"ARIOZCU1187FB3A3DC"
},
{
"name":"Thelonious Monk",
"hotttnesss":0.649332,
"id":"AR9PLH11187FB58A87"
},
{
"name":"Miles Davis",
"hotttnesss":0.697302,
"id":"AR7RTGF1187FB38793"
},
{
"name":"Miles Davis Quintet",
"hotttnesss":0.489603,
"id":"AR5DF1C1187FB4E94C"
},
{
"name":"Cannonball Adderley",
"hotttnesss":0.560071,
"id":"ARQ5TM41187FB3E97D"
},
{
"name":"Wayne Shorter",
"hotttnesss":0.548165,
"id":"ARO3CKW1187B9905A8"
},
{
"name":"Wynton Marsalis",
"hotttnesss":0.566708,
"id":"ARV3VEI1187B9AD5C9"
},
{
"name":"Sonny Rollins",
"hotttnesss":0.577764,
"id":"AR6Q4T91187B995616"
},
{
"name":"The Dave Brubeck Quartet",
"hotttnesss":0.570099,
"id":"ARLKR161187FB50694"
},
{
"name":"Kenny Burrell",
"hotttnesss":0.543388,
"id":"ARQYH461187FB3E975"
},
{
"name":"Stan Getz",
"hotttnesss":0.559735,
"id":"ARMGQLA1187B9AEBF8"
},
{
"name":"Dizzy Gillespie",
"hotttnesss":0.561122,
"id":"ARXA17J1187FB3B507"
},
{
"name":"Yusef Lateef",
"hotttnesss":0.513261,
"id":"ART95BW1187FB3AF79"
},
{
"name":"Bill Evans",
"hotttnesss":0.581819,
"id":"ARTLL9E1187FB4436F"
},
{
"name":"Freddie Hubbard",
"hotttnesss":0.524227,
"id":"ARU1K2U1187FB48529"
}
]
}
}
As far as I can tell, there isn't a way to page through the artists associated with a genre...