PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Friday the 28th of June, 2019

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[09:14:34] <jokke> hey there
[09:15:47] <jokke> the balancer has been running since yesterday and the distribution of chunks looks much better but the index size is still unchanged across the shards. I would've thought that it would decrease/increase proportionally to the chunks.
[09:16:16] <jokke> does it require an additional step to balance out the index?
[13:22:52] <cubud> Hi all
[13:24:09] <cubud> I have a document with a "data" node, that is an array of complex objects. In a single document I want to iterate all elements of the array and if the value of a specific attribute is "X" I want to change it to Y. Do I have to write a JS loop for this, or is there a query I could use?
[13:32:57] <GothAlice> cubud: If there is only one element to replace, you can use $elemMatch, then $set the "$" field to replace that array element, I believe.
[13:33:18] <GothAlice> If there is more than one array element to update, you're pooched and need to pull in the record and figure out the transformations to apply, or re-set the whole list.
[13:33:19] <GothAlice> list/array
[13:34:30] <GothAlice> Ref: https://docs.mongodb.com/manual/reference/operator/query/elemMatch/ + https://docs.mongodb.com/manual/reference/operator/projection/positional/#proj._S_
[13:34:45] <GothAlice> Dang, that's the projection $ operator, not the update one, but same behaviour.
[13:35:26] <GothAlice> filter: {some_array: {field: desired_value}} update: {$set: {"field.$": new_value}}
[13:35:59] <GothAlice> filter: {some_array: {field: desired_value}} update: {$set: {"some_array.$": new_value}} rather
[13:40:10] <cubud> GothAlice - Thanks, I think though that only matches the first element. I've written a forEach loop
[14:10:30] <GothAlice> As I mentioned. $ works for updating single array elements. More than that, you'll need to pull in, and either determine the individual $pull operations to perform, or in-memory modify the array then re-$set the whole thing.