8
n8n 中文网amn8n.com

n8n工作流:每日新闻聚合与MongoDB存储

中级

这是一个Market Research, Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 Code, Gmail, MongoDb, Perplexity, SplitInBatches 等节点。 使用Perplexity AI进行每日新闻聚合并存储到MongoDB

前置要求
  • Google 账号和 Gmail API 凭证
  • MongoDB 连接字符串
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "kpAcUnFPtxaqsGnZ",
  "meta": {
    "instanceId": "2726cca490aa82c0ebb012bdcdb3596cbc823e0d9b0e26be2ae4efed4df5b51c"
  },
  "name": "n8n 工作流:每日新闻聚合与 MongoDB 存储",
  "tags": [],
  "nodes": [
    {
      "id": "b00241ab-0355-4ada-acdb-56bea4f5d15a",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        64
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d4b2cdc4-39ec-4d3c-9b76-684cb485540e",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        778,
        -120
      ],
      "parameters": {
        "color": 3,
        "width": 508,
        "height": 200,
        "content": "最终通知"
      },
      "typeVersion": 1
    },
    {
      "id": "caee7461-f2b4-46d6-ab86-110bd0d85fc4",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        78,
        8
      ],
      "parameters": {
        "color": 6,
        "width": 228,
        "height": 216,
        "content": "Perplexity 新闻"
      },
      "typeVersion": 1
    },
    {
      "id": "1a0c7dc3-dc3c-498b-8567-ae92e9176245",
      "name": "Perplexity",
      "type": "n8n-nodes-base.perplexity",
      "position": [
        144,
        64
      ],
      "parameters": {
        "model": "sonar-pro",
        "options": {
          "searchRecency": "day"
        },
        "messages": {
          "message": [
            {
              "content": "Fetch the latest breaking news from the past few hours, focusing on major headlines, current events, and urgent updates. Prioritize high-impact global news (politics, economics, disasters, technology, conflicts) from reputable sources (e.g., Reuters, AP, BBC, CNN).\n\nReturn the results as a valid JSON array with each article structured as follows:\n\njson\n{\n  \"headline\": \"Concise headline (under 120 chars)\",  \n  \"timestamp\": \"ISO 8601 format (e.g., 2024-03-15T14:30:00Z)\",  \n  \"source\": \"Trusted source name (e.g., BBC News)\",  \n  \"summary\": \"1-2 paragraph neutral summary (avoid opinionated language)\",  \n  \"url\": \"Direct link to the article\",  \n  \"category\": \"Topical category (e.g., politics, technology)\",  \n  \"language\": \"en\",  \n  \"metadata\": {\n    \"priority\": \"high/medium/low\",  \n    \"location\": \"Geo-tag if relevant (e.g., 'Ukraine')\"  \n  }\n}\nRequirements:\n\nExclude paywalled/promotional content.\n\nEnsure timestamps are UTC.\n\nInclude at least 5-10 diverse news items.\n\n\nKey Improvements:\nSpecificity – Clarifies content focus (global, high-impact) and credible sources.\n\nData Quality – Explicitly excludes paywalled content and mandates neutral summaries.\n\nStructure – Uses nested metadata for extensibility (e.g., adding tags later)."
            }
          ]
        },
        "simplify": true,
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "id": "qKLBfuokGGYNrdJC",
          "name": "Perplexity account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "eceb97dd-a30a-4237-a992-ebd7e38f67b5",
      "name": "Perplexity 响应",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        64
      ],
      "parameters": {
        "jsCode": "// Get the string with the news array\nlet raw = $json[\"message\"];\n\n// Remove backticks and the ‘json’ tag if they exist\nraw = raw.replace(/```json|```/g, '').trim();\n\n// Parse the clean string into an array of objects\nconst noticias = JSON.parse(raw);\n\n// Returns each news item as an individual item for the Loop\nreturn noticias.map(noticia => ({ json: noticia }));"
      },
      "typeVersion": 2
    },
    {
      "id": "a77e0c7f-3597-4c98-8730-8af03a3a017b",
      "name": "新闻",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        -80
      ],
      "parameters": {
        "jsCode": "\nreturn [\n  {\n    json: {\n      noticias: items.map(item => item.json)\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "49c51d23-2786-4005-8f99-3df1bd048dc3",
      "name": "循环处理新闻",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        592,
        64
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0051a6ef-16d8-489c-8ad9-b28191a88599",
      "name": "数据库新闻",
      "type": "n8n-nodes-base.mongoDb",
      "notes": "Official Database",
      "position": [
        816,
        112
      ],
      "parameters": {
        "fields": "=headline,timestamp,source,summary,url,category,language,metadata",
        "options": {
          "dateFields": "={{ $json.headline }},{{ $json.timestamp }},{{ $json.source }},{{ $json.summary }},{{ $json.url }},{{ $json.category }},{{ $json.language }},{{ $json.metadata }}"
        },
        "operation": "insert",
        "collection": "news"
      },
      "credentials": {
        "mongoDb": {
          "id": "smjByRgHnSMlBLZV",
          "name": "MongoDB account"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "id": "c3cf8752-d188-44c5-8d85-762620670fe9",
      "name": "发送消息",
      "type": "n8n-nodes-base.gmail",
      "notes": "News registration confirmation",
      "position": [
        1040,
        -80
      ],
      "webhookId": "0ed03883-cced-4af4-a946-be91005b6108",
      "parameters": {
        "sendTo": "<YOUR EMAIL>",
        "message": "=<!DOCTYPE html> <html lang=\"es\">  <head>     <meta charset=\"UTF-8\">     <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">     <title>News</title>     <style>         body {             font-family: Arial, sans-serif;             background-color: #f4f4f4;             margin: 0;             padding: 0;         }          .container {             background-color: #ffffff;             width: 90%;             max-width: 600px;             margin: 20px auto;             padding: 20px;             border-radius: 5px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);         }          h1 {             color: #333333;             font-size: 22px;         }          p {             color: #555555;             font-size: 16px;             line-height: 1.5;         }          .button {             display: inline-block;             padding: 10px 20px;             background-color: #007bff;             color: #ffffff;             text-decoration: none;             border-radius: 4px;             margin-top: 10px;         }          .footer {             font-size: 12px;             color: #888888;             text-align: center;             margin-top: 20px;         }     </style> </head>  <body>     <div class=\"container\">         <h1>Hi!!</h1>         <p>             We are pleased to inform you that the registration of news in MongoDB was successful!         </p>         <p>Thanks.</p>         <div class=\"footer\">             © 2025 News World.         </div>     </div> </body>  </html> ",
        "options": {
          "appendAttribution": false
        },
        "subject": "=[ News ] Record of all news items"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "Qq401GIyTl33eVdh",
          "name": "Gmail account 2"
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "da552b54-3fce-416e-bb6e-fcc5e5cacf4f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        -464
      ],
      "parameters": {
        "width": 1008,
        "height": 1632,
        "content": "## n8n 工作流:每日新闻聚合与 MongoDB 存储"
      },
      "typeVersion": 1
    },
    {
      "id": "5f8fde92-09a5-44a2-9e8e-efebfcb84fd9",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 1504,
        "height": 672,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a765923b-a9ab-4567-a08f-132d54451d50",
  "connections": {
    "News": {
      "main": [
        [
          {
            "node": "Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DB News": {
      "main": [
        [
          {
            "node": "Loop Over News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Perplexity": {
      "main": [
        [
          {
            "node": "Response Perplexity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Message": {
      "main": [
        []
      ]
    },
    "Loop Over News": {
      "main": [
        [
          {
            "node": "News",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "DB News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Perplexity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Response Perplexity": {
      "main": [
        [
          {
            "node": "Loop Over News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 市场调研, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量11
分类2
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Samuel Heredia

Samuel Heredia

@sheredia

I like to believe that I can contribute to creating a better world with the developments I make :)

外部链接
在 n8n.io 查看

分享此工作流