Reputation: 65
I am working on a multi-player card game (think Yu-gi-oh) based on real-world data. I have a collection "data" with data on individual items and another collection "cards" with actual issued cards in the game.
Cards have many-to-1 relationship with data-items (so one data-item is used to fill parameter-data for a number of copies of a single card, but with different owners).
"Cards" are published to client(s) as a local sub-set collection with all the "data"-items needed for all client-side "cards" items from client publication of "cards".
During the game, and especially in test phase, I need to "produce batches of cards" (and perhaps perform other setup and fine-tuning functions) from command-line/terminal/shell using helper functions with parameters (like cards.issue(10) that would create 10 new cards).
I would like to do that from command-line/terminal/shell to avoid writing admin front-end until I am sure about what will be done manually, and what automatically.
Where would I put a .js file with such helping scripts (functions with parameters) and how would I run them from terminal? How can I access meteor (server-side) objects from terminal/shell?
Upvotes: 0
Views: 620
Reputation: 19544
The easiest way to achieve this is a script in node.js.
1) You put those files whenever you want, just make sure they're not in the Meteor's scope of interest. So if you want to put them in your project directory, put them in a hidden (starting with a .
) subfolder.
2) You run those files as typical node script: node path/to/file.js
.
3) You don't need to access Meteor structure from that script, just the database. To do so, you need a Mongo driver (node mongodb
package - here's the handy documentation), then:
Load it:
var MongoClient = require('mongodb').MongoClient;
Connect to the local db:
MongoClient.connect('local_db_url', function(err, db) {
...
});
Inside the connect callback, insert your objects:
var cards = db.collection('cards');
cards.insert(card, {safe: true});
Upvotes: 2