Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

328
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda