Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
removing data in nested arrays in mongodb shell

i'm new in Nosql. i'm using Mongodb shell for the first time. i've seen other related solutions but non of them is working for me. i have an object that contains several nested arrays i want to remove the data that are not in 2016. the collection looks like this.

"_id" : ObjectId("58754aa6b10700f77b90c018"),
"results" : [
    {
        "series" : [
            {
                "name" : "light",
                "columns" : [
                    "time",
                    "agent_id",
                    "device_id",
                    "rpi_id",
                    "type",
                    "value"
                ],
                "values" : [
                    [
                        "1970-01-01T00:00:01.474264311Z",
                        null,
                        "2:1",
                        "b07882d6-5c28-597b-89f9-d250f74b0bad",
                        "light",
                        "231"
                    ],
                    [
                        "1970-01-01T00:00:01.474280348Z",
                        null,
                        "1:1",
                        "b07882d6-5c28-597b-89f9-d250f74b0bad",
                        "light",
                        "404"
                    ],
                    [
                        "1970-01-01T00:00:01.474280526Z",
                        null,
                        "2:1",
                        "b07882d6-5c28-597b-89f9-d250f74b0bad",
                        "light",
                        "239"
                    ],
                    [
                        "2016-12-21T23:36:32Z",
                        "fce19d9c-3bba-5b18-9854-f86776b47a9c",
                        "4",
                        null,
                        null,
                        "1019"
                    ],
                    [
                        "2016-12-21T23:36:56Z",
                        "fce19d9c-3bba-5b18-9854-f86776b47a9c",
                        "1",
                        null,
                        null,
                        "1023"
                    ],
                    [
                        "2016-12-21T23:37:00Z",
                        "fce19d9c-3bba-5b18-9854-f86776b47a9c",
                        "5",
                        null,
                        null,
                        "1022"
                    ]
                ]
            }
        ]
    }
]

for example i tried this query to find them but the result is the whole collection:

db.lights.find({"results.series.values": {$elemMatch : {$elemMatch: {$not : /^2016/} } } })

i'll be so grateful if anyone could answer it.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda