Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you seem to be familiar with ORM pattern I would recommend using the <a href="http://mongoosejs.com/" rel="noreferrer">"mongoose" module</a>. Though I would guess that you'll have a hefty learning curve with NodeJS and Mongo to make a solid app. </p> <p>Here's a working example to get you started though:</p> <pre><code>#! /usr/bin/node var mongoose = require('mongoose'); mongoose.connect('localhost', 'test'); var fs = require('fs'); var lineList = fs.readFileSync('mytest.csv').toString().split('\n'); lineList.shift(); // Shift the headings off the list of records. var schemaKeyList = ['RepName', 'OppID', 'OppName', 'PriorAmount', 'Amount']; var RepOppSchema = new mongoose.Schema({ RepName: String, OppID: String, OppName: String, PriorAmount: Number, Amount: Number }); var RepOppDoc = mongoose.model('RepOpp', RepOppSchema); function queryAllEntries () { RepOppDoc.aggregate( {$group: {_id: '$RepName', oppArray: {$push: { OppID: '$OppID', OppName: '$OppName', PriorAmount: '$PriorAmount', Amount: '$Amount' }} }}, function(err, qDocList) { console.log(util.inspect(qDocList, false, 10)); process.exit(0); }); } // Recursively go through list adding documents. // (This will overload the stack when lots of entries // are inserted. In practice I make heavy use the NodeJS // "async" module to avoid such situations.) function createDocRecurse (err) { if (err) { console.log(err); process.exit(1); } if (lineList.length) { var line = lineList.shift(); var doc = new RepOppDoc(); line.split(',').forEach(function (entry, i) { doc[schemaKeyList[i]] = entry; }); doc.save(createDocRecurse); } else { // After the last entry query to show the result. queryAllEntries(); } } createDocRecurse(null); </code></pre> <p>Your data in "mytest.csv":</p> <pre><code>Rep Name,Opp ID,Opp Name,Prior Amount,Amount Rep 1,1234561,Opp 1,10000,8000 Rep 1,1234562,Opp 2,15000,9000 Rep 2,1234563,Opp 3,20000,10000 Rep 1,1234564,Opp 4,25000,11000 Rep 2,1234565,Opp 5,30000,12000 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload