title: Meteor / python / mongoDB - How do I update the mongoDB from a background running process?
body: <p>I've started creating a meteor app and I want to insert Documents in one of the mongoDB Collections I define using a background task.</p>
  
  <p>Think for example that every day I'm reading an rss feed and scraping a website for news-titles.</p>
  
  <p><strong>Requirement</strong></p>
  
  <ol>
  <li>Read the rss feed and scrape the necessary website.</li>
  <li>Put the new titles into the mongoDB Collection used by the meteor App.</li>
  </ol>
  
  <p><strong>What I know</strong></p>
  
  <p>I know how to do 1. using python, with <code>requests</code> and other libraries.
  I know how to add information into a collection through javascript in meteor but <em>NOT</em> through a background task by following the <code>todo</code> example application tutorial.</p>
  
  <p><strong>Possible solutions</strong></p>
  
  <ol>
  <li>Get the data in python and then through python add that data to the mongoDB Collection. This would then run on the server on some kind of background process.</li>
  <li>Use some kind of library from meteor that allows me to run background tasks and webscraping, that I can then use to update the collection.</li>
  </ol>
  
  <p>minimal example taken is from <a href="https://www.meteor.com/tutorials/react/collections" rel="nofollow">this step of the todo app</a>.</p>
  
  <p>The step I want to automate:</p>
  
  <pre><code>meteor mongo
  db.tasks.insert( { text : 'New title' , createdAt: new Date() } );
  </code></pre>
  
  <p>where <code>New title</code> is a result of some scrapping / rss feed.</p>
  
  <p>What is the best way to achieve this? I'm relatively fluent in python but completely new to JS and meteor.</p>
  
  <p><strong>Other comments</strong></p>
  
  <p>Also, I haven't included this in this example below but I will also want to use the <code>accounts-ui</code> and <code>accounts-password</code> packages and will remove the <code>insecure</code> package. Not sure how this affects the implementation of the background process.</p>
  
  <p><strong>minimal example</strong></p>
  
  <p><em>(sorry if this isn't very minimal but not sure how to make it smaller)</em></p>
  
  <ul>
  <li>client
  
  <ul>
  <li>main.html</li>
  <li>main.jsx</li>
  </ul></li>
  <li>server
  
  <ul>
  <li>main.js</li>
  </ul></li>
  <li>imports
  
  <ul>
  <li>api
  
  <ul>
  <li>tasks.js</li>
  </ul></li>
  <li>ui
  
  <ul>
  <li>App.jsx</li>
  <li>Task.jsx</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <blockquote>
    <p>client/main.html</p>
  </blockquote>
  
  <pre><code>&lt;head&gt;
    &lt;title&gt;Todo List&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id='render-target'&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <blockquote>
    <p>client/main.jsx</p>
  </blockquote>
  
  <pre><code>import React from 'react';                                                                  
  import { Meteor } from 'meteor/meteor';
  import { render } from 'react-dom';
  
  import App from '../imports/ui/App.jsx';
  
  Meteor.startup( () =&gt; {
      render( &lt;App/&gt; , document.getElementById( 'render-target' ) );
  });
  </code></pre>
  
  <blockquote>
    <p>server/main.js</p>
  </blockquote>
  
  <pre><code>import '../imports/api/tasks.js'
  </code></pre>
  
  <blockquote>
    <p>imports/api/tasks.js</p>
  </blockquote>
  
  <pre><code>import { Mongo } from 'meteor/mongo';                                                       
  
  export const Tasks = new Mongo.Collection( 'tasks' );
  </code></pre>
  
  <blockquote>
    <p>imports/ui/App.jsx</p>
  </blockquote>
  
  <pre><code>import React , { Component , PropTypes } from 'react';                                      
  import { createContainer } from 'meteor/react-meteor-data';
  
  import { Tasks } from '../api/tasks.js';
  
  import Task from './Task.jsx';
  
  class App extends Component {
  
      renderTasks() {
          return this.props.tasks.map( ( task ) =&gt; (
              &lt;Task key={task._id} task={task} /&gt;
          ) );
      }   
  
      render() {
          return (
              &lt;div className='container'&gt;
                  &lt;header&gt;
                      &lt;h1&gt;Todo List&lt;/h1&gt;
                  &lt;/header&gt;
  
                  &lt;ul&gt;
                      { this. renderTasks() }
                  &lt;/ul&gt;
              &lt;/div&gt;
          );
      }   
  }
  
  App.propTypes = { 
      tasks : PropTypes.array.isRequired,
  };
  
  export default createContainer( () =&gt; {
      return {
          tasks : Tasks.find( {} ).fetch(),
      };  
  } , App );
  </code></pre>
  
  <blockquote>
    <p>imports/ui/Task.jsx</p>
  </blockquote>
  
  <pre><code>import React, { Component , PropTypes } from 'react';                                       
  
  // Task component - represents a single todo item
  export default class Task extends Component {
      render() {
          return (
              &lt;li&gt;{this.props.task.text}&lt;/li&gt;
          );
      }   
  }
  
  Task.propTypes = { 
      // This component gets the task to display through a React prop.
      // We can use propTypes to indicate it is required
      task: PropTypes.object.isRequired,
  };
  </code></pre>