-
Notifications
You must be signed in to change notification settings - Fork 19
/
data_example.js
39 lines (34 loc) · 976 Bytes
/
data_example.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
var stdin = process.stdin;
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
//Modify default: 'A' changing the letter execution per execution
var BoardSchema = new Schema({
type : { type: Number, validate: /[0|1]/, default: 1 },
value : { type: String, default: 'A'},
x : { type: Number, default: 10 },
y : { type: Number, default: 10 }
});
var db = mongoose.connect('mongodb://localhost/blackboard');
var model = mongoose.model('Data', BoardSchema);
var Data = mongoose.model('Data');
var i=0;
for(i;i<10;i++) {
var data = new Data();
data.x=Math.ceil(Math.random()*1000);
data.y=Math.ceil(Math.random()*1000);
data.save(function(err) {
if(err) { throw err; }
console.log('saved');
});
}
/*data.save(function(err){
if(err) { throw err; }
console.log('saved');
Data.find({value: 'B'}, function(err, docs) {
if(err) { throw err; }
docs.forEach(function(doc){
console.log(doc);
});
mongoose.disconnect();
});
});*/