Created
November 9, 2011 18:12
-
-
Save aheckmann/1352317 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('./mongoose'); | |
var Schema = mongoose.Schema; | |
mongoose.connect('localhost', 'testing_604'); | |
// original git://gist.github.com/1352079.git | |
var CalendarEvent = new Schema({ | |
title : String, | |
allDay : Boolean, | |
start : Date, | |
end : Date, | |
url : String, | |
color : String, | |
ref : String | |
}); | |
var CalendarMonth = new Schema({ | |
id : Number, | |
allEvents : [CalendarEvent] | |
}); | |
var CalendarEventReference = new Schema({ | |
id : Number, //Users id | |
ref : [CalendarMonth] | |
}); | |
var A = mongoose.model('A', CalendarEventReference); | |
var CalendarEvent = mongoose.model('C', CalendarEvent); | |
mongoose.connection.on('open', function () { | |
A.remove({}, function () { | |
A.create({ id: 1, ref: [{id:9, allEvents:[]}] }, function (err) { | |
if (err) return console.error(err.stack); | |
var theEvent = new CalendarEvent(); | |
theEvent.title = 'my title' | |
theEvent.allDay = true | |
theEvent.start = new Date | |
theEvent.end = new Date | |
theEvent.url = "empty"; | |
theEvent.color = 'greeeeeen' | |
theEvent.ref = 'the ref'; | |
A.findOne({ id: 1}, function(err, resultReference){ | |
if (err) return console.error(err.stack); | |
resultReference.ref[0].allEvents.push(theEvent); | |
resultReference.save(function(err){ | |
if (err) return console.error(err.stack); | |
console.error('Succesfully saved'); | |
mongoose.connection.close(); | |
}); | |
}); | |
}); | |
}); | |
}); |
Author
aheckmann
commented
Nov 10, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment