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 query = { name: 'Sprinkls' }; | |
var update = { name: 'Sprinkles' }; | |
var options = { new: false }; | |
Cat.findOneAndUpdate(query, update, options, function (err, cat) { | |
if (err) .. | |
render('cat', cat); | |
}); |
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 update = { name: 'Sprinkles' }; | |
Cat.findByIdAndUpdate(id, update, function (err, cat) { | |
if (err) .. | |
render('cat', cat); | |
}); |
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
Cat.findById(id, function (err, cat) { | |
if (err) ... | |
cat.name = 'Sprinkles' | |
cat.save(function (err) { | |
if (err) .. | |
render('cat', cat); | |
}) | |
}) |
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
Post.findById(postId, function (err, post) { | |
// handle errors .. | |
var comment = post.comments.id(commentId); | |
comment.body = updatedText; | |
post.save(callback); | |
}); |
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
Post.findById(postId, function (err, post) { | |
// handle errors .. | |
post.comments.push({ body: someText, user: userId }); | |
post.save(callback); | |
}) |
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 commentSchema = new Schema({ | |
body: String | |
, user: Schema.ObjectId | |
, created: { type: Date, default: Date.now } | |
}); | |
var postSchema = new Schema({ comments: [commentSchema] }); | |
var Post = mongoose.model('Post', postSchema); |
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_11074799'); | |
mongoose.connection.on('error', function () { | |
console.error(arguments); | |
}); | |
var UserSchema = new Schema({ name: String }); |
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 times = 0; | |
function loop () { | |
++times; | |
if (times >= 30000) throw new Error('fake stack overflow'); | |
return loop; | |
} | |
function start () { | |
var fn; | |
while (fn = loop()) fn(); |
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 times = 0; | |
function loop () { | |
++times; | |
if (times >= 30000) return; | |
return loop; | |
} | |
function start () { | |
var fn; | |
while (fn = loop()) fn(); |
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 times = 0; | |
function loop () { | |
++times; | |
loop(); | |
} | |
try { | |
loop(); | |
} finally { | |
console.log('stack overflow after %d loops', times) |