Hi there, are there any ways to insert a document using aggregation pipeline?
I am not sure of your use-case but you could take a look at
Hi @steevej , I am pretty much looking for a aggregation pipeline substitution of db.collection().insert() function
That is what $merge is about. It insert documents, created by the execution of an aggregation, into a target collection.
An alternative is $out.
I am pretty much looking for a aggregation pipeline substitution of db.collection().insert()
Why can’t you just use
insert? Can you elaborate on the functionality you need? Rather than
$merge I suspect you probably want to use
upsert flag set to true and aggregation pipeline syntax to specify the update (available since version 4.2).