0

I have a MongoDB collection, and I need to return a field of a document in collection, in which the first field address is equal to the one I give.

This is an example of my Test document

{
    "_id": "mtXjL56DgJNiwr6lI5",
    "state": {
        "label": "disconnected",
        }
    },
    "name": "Hey",
    "senders": [
        "zAxNarwAE2AnvLA8P",
        "me3AWg85YDvWMShKY",
        "e3wADkdLDKp5MEKYW",
        "4dzdz8Xaw7aQM7ZeW",
    ],
    "hard": "4.8",
} 

So when I find zAxNarwAE2AnvLA8P equal the senders.0 , I'll get all the senders without the first one

"senders": [ "me3AWg85YDvWMShKY", "e3wADkdLDKp5MEKYW", "4dzdz8Xaw7aQM7ZeW", ]

Alex
  • 8,353
  • 9
  • 45
  • 56
EyTa
  • 109
  • 3
  • 10
  • @neil Lunn i want the first element to match the one i tapped. – EyTa May 29 '18 at 09:59
  • What you are asking is exactly the same as a very common question, it's just that you want the "reverse" where instead of returning the matched array elements you want everything except the match. It's really just the same `$filter` application but using `$ne` to exclude the element. That said, if you are only trimming "one" element, you may as well just return the whole array anyway. But the process is there if you want it. – Neil Lunn May 29 '18 at 10:00

0 Answers0