How can I pull from the following MongoDB document all null
values in, so that there are no more null
values in the groups array? I want to do it in NodeJS.
(In my real document I have more embedded documents in the tables array with the same structure)
{
"_id": {
"$oid": "5a4267b9734d1d5b99268cbe"
},
"department": "waeldlerStubeKristallStube",
"tables": [
{
"arrayIndex": 0,
"department": "waeldlerStubeKristallStube",
"number": "50",
"topValue": "139",
"leftValue": "455",
"bgColor": "#ffffff",
"isBesetzt": "false",
"placeholder": "true",
"border": "solid 3px #f3efe4",
"width": "40",
"height": "35",
"groups": [
null,
{
"nameValue": "Hunziker, Iveta",
"zimmernummerValue": "460",
"anreiseValue": "16.02.2018",
"abreiseValue": "25.02.2018",
"personenAnzahlValue": "2/1",
"notiz2Value": "2*50 Euro Spa Taler",
"notiz1Value": "2 Erw neu + 1 Baby geänderte reservierung neues Datum",
"traceValue": "-",
"bemerkungValue": "-"
},
null
]
}
]
}
It seems to me that I need to update the document, query all the groups with the value null, which is in the tables array and pull the null with
tables.$.groups
including a positional operator. I had also a look at the following post: MongoDB pull element from array two levels deep and came up with this try:
db.hubertusTables.update({"tables.groups": null},{ $pull: { "tables.$.groups": null} }, { multi: true});
My try does not work. I get the following response:
{"n":2,"nModified":0,"opTime":{"ts":"6526469489381343253","t":4},"electionId":"7fffffff0000000000000004","ok":1}
Thanks a lot for the effort!