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

111
Visualizações
Mongo Script file - Export the execution result to CSV file after checking in two collections

I want to export the result to CSV file after executing the script file using mongo shell.

topoList = db.collection1.aggregate([{
    $match: {
        equipments: {
            $elemMatch: {
                "identification": {
                    $exists: true;
                }
            }
        }
    }
}, {
    $unwind: "$equipments"
}]);
print("--- collection1 : load" + topoList.length)
while (topoList.hasNext()) {
    print("--- Inside while: load")
    topo_id = topoList.next().equipments
    
    while(topo_id.hasNext()){
        collection2_id = topo_id.next()._id
        print(" *  " + collection2_id)
    }
    print("- " + topo_id)
    gatewayList = db.collection2.find({
        type: 'GATEWAY',
        collection1Id: topo_id
    }, {
        _id: 1
    })
    print("--- collection1 :" + topo_id)
    db.collection1.find({
        _id: topo_id
    })
    print("---- collection2s")
    collection2sList = db.collection2.find({
        collection1Id: topo_id
    })
    while (collection2sList.hasNext()) {
        collection2_id = collection2sList.next()._id
        print(" *  " + collection2_id)
        db.collection2.find({
            _id: collection2_id
        })
    }
    print("----- end of collection1")
}
print("----- end of collection1")

How to export the result to CSV file? Specifically , the resulted id's ( _id: collection2_id ) should be exported to CSV file.

about 4 years ago · Juan Pablo Isaza
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