MongoDB Export Collection to CSV

Yes, that's right I am using my blog to post a sticky note to help me remember how to export mongo collection data.

$ mongoexport --host localhost --db dbname --collection name --csv --out data.csv --fields node1,node2,node3

Yes, that's right I am using my blog to post a sticky note to help me remember how to export mongo collection data. $ mongoexport --host localhost --db dbname --collection name --csv --out data.csv --fields node1,node2,node3…

Read More

Mongoose Populate

I found this to be extremely helpful recently when dealing with MongoDB NodeJS joins. Pay close attention to this = "stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]"

var mongoose = require('mongoose')  
  , Schema = mongoose.Schema

var personSchema = Schema({  
  _id     : Number,
  name    : String,
  age     : Number,
  stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});

var storySchema = Schema({  
  _creator : { type: Number, ref: 'Person' },
  title    : String,
  fans     : [{ type: Number, ref: 'Person' }]
});

var Story  = mongoose.model('Story', storySchema);  
var Person = mongoose.model('Person', personSchema);  

then use .populate() to grab the story's ref

Story  
.findOne({ title: 'Once upon a timex.' })
.populate('_creator')
.exec(function (err, story) {
  if (err) return handleError(err);
  console.log('The creator is %s', story._creator.name);
  // prints "The creator is Aaron"
})

I found this to be extremely helpful recently when dealing with MongoDB NodeJS joins. Pay close attention to this = "stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]" var mongoose = require('mongoose') , Schema = mongoose.Schema var personSchema = Schema({ _id : Number, name : String, age : Number, stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }] }); var…

Read More

KANO

This weekend I put together my first open source project called Kano. You can learn more about the project by visiting here or visiting my github https://github.com/erictherobot/kano

This weekend I put together my first open source project called Kano. You can learn more about the project by visiting here or visiting my github https://github.com/erictherobot/kano…

Read More

Shutting of my LAMP and turning on my MEAN...stack

I've been a PHP guy for a long time. Like all computer languages, I've learned through trial and error. PHP just sort of fell on me and I hung out with it because it was well documented, open source, most hosting companies supported it, most of my friends used it. For me, PHP was understood.

PHP Frameworks. Over the years I started thinking of finding a silver bullet. Something that I could quickly understand and hit the ground running and PHP Frameworks was that silver bullet for me. In the past I've tried Yii, Codeigniter, FuelPHP, CakePHP, Lithium, Kohana, Laravel, PhalconPHP, and about 30 more that are worth mentioning, I'm just not going to because from here on out I am moving over to a MEAN (Mongo + ExpressJS + AngularJS + NodeJS) stack... well actually for me at the moment I'm skipping AngularJS and just using a MEN Stack.

What generally takes me one week to do in PHP is now taking me two hours in NodeJS and it is soooo much lighter and beautiful. Time saver! Lightbulbs! Inspiration! New Chapter!

I still love you PHP, but I'm shutting down the LAMP stack and getting seriously MEAN!

I've been a PHP guy for a long time. Like all computer languages, I've learned through trial and error. PHP just sort of fell on me and I hung out with it because it was well documented, open source, most hosting companies supported it, most of my friends used it.…

Read More