Mongodb aggregate pipeline templates

Mongodb aggregate is a powerful operation in data query for analysis purpose and so on but I find I always need to refer to the official documentation or AI tools like ChatGPT or Perplexity for even very simple syntax when trying to compose aggregate operations, so I summarize some commonly used patterns as templates for quick reference at work.

Insert into mongodb with DBRef

How to insert a new object into mongodb using pymongo with reference to other objects using DBRef.