last day (15 days later) » 

1:13 PM
0
Q: set and updateMany behaviour with array of objects in mongoDB document

megI have a document in mongoDB which contains these two arrays- "CS_Currency": [ { "name": "AUD" }, { "name": "IVP" } ], "TestRef": [ { "name": "Reftest" }, { "name": "Ref5" }, ...

 
Is "Entity_Type_Value" an array of objects or just a single object?
 
meg
Entity_Type_Value: { name:'Deal'} Entity_Type_Value is going to be an object
 
Are you sure it's not something like "Entity_Type_Value": [{ "name": "Deal" }, { "name": "No Deal" }]? Because that replicates your issue perfectly. If it's just a single object and not an array, then it works as expected
 
meg
Hi sorry, yes Entity_Type_Value:[ { name:'Deal'} ] Entity_Type_Value is going to be an array of object, but this array will contain only one object
Is there any way to resolve this issue or make it work? Why is this happening when 'Entity_Type_Value' is an array? @aneroid
 
Next time, Read: How to create a Minimal, Reproducible Example, and How to Ask.. You skipped an important piece of information in your example data which turned out to the be root cause of your issue. You even had the field in your query but didn't include it in the data. When asked, you first said it was not an array and then said it was an array when I asked again.
 
meg
1:14 PM
sorry, I had no idea Entity_Type_Value could be causing this issue, hence provided little to no attention on it.
 
the whole point of asking on StackOverflow is that you didn't know
and if it's in your query, it has to be in your example data
and after I asked, you said it was an object, not an array
 
meg
got it, will keep this in mind, pardon me this time
 
spent more time investigated different combos for the error than the actual result
yeah, it happens, it's okay
 
meg
okay
 
just understand other people are taking an effort to answer. so you should put in the same effort while asking :-)
 
meg
1:17 PM
yes definitely, thanks for your answer!
 
also, if "Entity_Type_Value" will always be an array with just one object, then just make it an object, instead of an-array-of-one-object
read the part of my answer about related-arrays in the same object - that's bad design. put related info in one object; especially if it's already in the same document
 

last day (15 days later) »