Skip to content

Instantly share code, notes, and snippets.

@diegograssato
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegograssato/2888a81297c9b5fccecb to your computer and use it in GitHub Desktop.
Save diegograssato/2888a81297c9b5fccecb to your computer and use it in GitHub Desktop.
Exemplo de DBRef
Host.findOne({nome: req.body.host})
.populate('dominio')
.exec(function (err, host) {
console.log(host);
});
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Dominio = new Schema({
_id: { type: Schema.ObjectId },
nome: { type: String, default: '' },
ipAddress: { type: String },
hmac: { type: String },
ativo: { type: String },
});
module.exports = mongoose.model('Dominio', Dominio);
{
"_id" : ObjectId("539f82200ace836f35c52f2c"),
"nome" : "dtux.org",
"ipAddress" : "192.168.0.1",
"hmac" : "Kdiego.org.+157+14340.private",
"alteracoes" : 1,
"ativo" : true,
"criadoEm" : ISODate("2014-06-16T20:47:44.369-03:00"),
"atualizadoEm" : ISODate("2014-06-16T20:47:50.081-03:00")
}
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Dominio = require('./Dominio');
var Host = new Schema({
nome: { type: String, default: '' },
ativo: { type: String, default: '' },
ipAddress: { type: String, default: '' },
dominio: { type : Schema.ObjectId, ref : 'Dominio' }
}, { collection: 'Host' });
module.exports = mongoose.model('Host', Host);
{
"_id" : ObjectId("539f82200ace836f35c52f39"),
"nome" : "pc5",
"ip_address" : "6b1328a2d1d06b1be5ca1078e6e8810d2550b48e",
"ipAddress" : "192.168.0.5",
"dominio" : {
"$ref" : "Dominio",
"$id" : ObjectId("539f82200ace836f35c52f2c"),
"$db" : "simpleDDNS"
},
"alteracoes" : 0,
"ativo" : true,
"criadoEm" : ISODate("2014-06-16T20:47:44.379-03:00"),
"atualizadoEm" : ISODate("2014-06-16T20:47:44.379-03:00")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment