Skip to content

Instantly share code, notes, and snippets.

@zoranf
Created April 3, 2013 01:42
Show Gist options
  • Save zoranf/5297787 to your computer and use it in GitHub Desktop.
Save zoranf/5297787 to your computer and use it in GitHub Desktop.
var url = "url from nodejitsu",
coll = ['games'],
db = require('mongojs').connect(url, coll);
// A user model object
function user(username, password, nickname) {
this.username = username;
this.password = password;
this.nickname = nickname;
}
// A game model object
function game(name, image, type) {
this.name = name;
this.image = image;
this.type = type;
}
var schnapssen_type = { type1: "2",
type2: "3",
type3: "4" },
schnapssen = new game("Schnapssen", "/images/schnapssen.jpg", schnapssen_type);
db.games.ensureIndex({ name : 1}, {unique : true} );
// Add schnapssen
db.games.save(schnapssen, function(err, saved_game) {
if (err || !saved_game.length)
console.log('Error - [saving] ->' + err);
else
console.log('Success - [saving]');
});
// Get games
db.games.find(function(err, games) {
if (err || !games.length)
console.log('Emptey database ->' + err);
else games.forEach(function(game) {
console.log('Game: ' + game.type.type1);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment