-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.js
53 lines (40 loc) · 1.09 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var mongoose = require('mongoose');
var db = mongoose.connection;
db.on('error', console.error);
db.once('open', function() {
// Create your schemas and models here.
});
var registro1 = new mongoose.Schema({
nome: { type: String }
, sobrenome: String
, status: {type: String, default: "inativo(a)"}
, atualizado_em: { type: Date, default: Date.now }
});
var registro2 = new mongoose.Schema({
nome: { type: String }
, nota: Number
, universidade: String
});
var Registro1 = mongoose.model('Registro1', registro1);
var Registro2 = mongoose.model('Registro2', registro2);
mongoose.connect('mongodb://localhost/meuBancoTeste');
//salvando registro 1
var registro = new Registro1({
nome: "Raul"
, sobrenome: "Sena Ferreira"
, status: "ativo"
});
registro.save(function(err, registro) {
if (err) return console.error(err);
//console.dir(registro);
});
//salvando registro 2
var registro = new Registro2({
nome: "Raul"
, nota: 10
, universidade: "UFRRJ"
});
registro.save(function(err, registro) {
if (err) return console.error(err);
//console.dir(registro);
});