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

329
Visualizações
How can I combine find + insert in mongodb like oracle SQL?

In oracle I can:

INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

Is there any command in mongodb like this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes, with the aggregation framework you can run a pipeline that uses the $out operator as means to write the results of the query to another collection.

Consider running the following aggregate operation:

db.tbl_temp1.aggregate([
    { "$match": { "fld_order_id": { "$gt": 100 } } },
    { "$project": { "fld_id": "$fld_order_id" } },
    { "$out": "tbl_temp2" }
])

In the above aggregation, the $match pipeline step acts as a filter on the document stream to allow only matching documents to pass unmodified into the next pipeline stage:

{ "$match": { "fld_order_id": { "$gt": 100 } } },

and is equivalent to the SQL's WHERE clause

WHERE tbl_temp1.fld_order_id > 100

The next $project pipeline stage selects/reshapes each document in the stream, such as adding new fields or removing existing fields:

{ "$project": { "fld_id": "$fld_order_id" } },

is the same as

SELECT tbl_temp1.fld_order_id AS fld_id

and the final $out operator stage

{ "$out": "tbl_temp2" }

writes the resulting documents of the aggregation pipeline to a collection, akin to

INSERT INTO tbl_temp2 
over 4 years ago · Santiago Trujillo Relatório
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