INSERT INTO collection_name [ (column_alias [, ...]) ] select_query
INSERT Inserts result of a query into a collection. Individual values cannot be inserted.
collection_nameis the collection into which query results are ingested.
column_aliasrenames fields in the result rows. If specified, this list must contain as many
items as the number of fields selected by the
select_queryis a valid
The ingestion of query results into the specified collection begins after the
SELECT command finishes successfully. The console will display
num_docs_inserted ( the API equivalent is
result_set_document_count) which is the result count of the
SELECT command. If there is an ingest transformation on the collection, it will then be applied to the result docs before they are finally inserted into the collection.
To verify that your collection has been updated, you can call GET on the query to find the
last_offset performed by the INSERT and then follow these directions.
Below we cover common uses of
To update some documents in a collection. Note that following queries select
_id column, so a document with specified id gets updated.
INSERT INTO collection1 SELECT _id, price + 10 AS price FROM collection1 where price < 5
INSERT INTO collection1 SELECT _id, NULL AS age FROM collection1
To replicate a collection:
INSERT INTO collection2 SELECT * FROM collection1