Skip to content

Instantly share code, notes, and snippets.

@suissa
Created April 30, 2015 22:39
Show Gist options
  • Save suissa/7aa19300578410269baf to your computer and use it in GitHub Desktop.
Save suissa/7aa19300578410269baf to your computer and use it in GitHub Desktop.
var Beer = require('./model')
, Cervejaria = require('./model-cervejaria')
;
Cervejaria
.findOne()
.populate('beers')
.exec(function (err, cervejaria) {
if (err) return console.log('Erro: ', err);
console.log('Cervejaria', cervejaria);
// prints "The creator is Aaron"
});
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/workshop-be-mean-abril-2015');
var db = mongoose.connection;
db.on('error', function(err){
console.log('Erro de conexao.', err)
});
db.on('open', function () {
console.log('Conexão aberta.')
});
db.on('connected', function(err){
console.log('Conectado')
});
db.on('disconnected', function(err){
console.log('Desconectado')
});
var Schema = mongoose.Schema;
var _schema = { name: { type: String, default: '' }
, created_at: { type: Date, default: Date.now }
, beers: [{ type: Schema.Types.ObjectId, ref: 'Beer' }]
}
, Cervejariachema = new Schema(_schema);
module.exports = Cervejaria = mongoose.model('Cervejaria', Cervejariachema);
// var dados = {
// name: 'SuissaBier'
// , beers: ['554188e6a43b404a3e0fc5f4']
// }
// var model = new Cervejaria(dados);
// model.save(function (err, data) {
// if (err){
// console.log('Erro: ', err);
// }
// else{
// console.log('Cerveja Inserida: ', data);
// }
// });
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/workshop-be-mean-abril-2015');
var db = mongoose.connection;
db.on('error', function(err){
console.log('Erro de conexao.', err)
});
db.on('open', function () {
console.log('Conexão aberta.')
});
db.on('connected', function(err){
console.log('Conectado')
});
db.on('disconnected', function(err){
console.log('Desconectado')
});
var Schema = mongoose.Schema;
var _schema = { name: { type: String, default: '' }
, description: { type: String, default: '' }
, alcohol: { type: Number, min: 0, default: '' }
, price: { type: Number, min: 0, default: '' }
, category: { type: String, default: ''}
, created_at: { type: Date, default: Date.now }
}
, BeerSchema = new Schema(_schema);
module.exports = mongoose.model('Beer', BeerSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment