Created
March 19, 2011 03:18
-
-
Save thiagofm/877192 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 db = mongoose.connect('mongodb://localhost/mydb'); | |
var Schema = mongoose.Schema; | |
var Posts = new Schema({ | |
name : String, | |
subject: String, | |
comment : String, | |
password: String, | |
}); | |
mongoose.model('Post', Posts); | |
function createNewPost(){ | |
var Post = mongoose.model('Post'); | |
var post = new Post(); | |
post.subject='hshja'; | |
post.comment ='ahsjashjas'; | |
post.save(function(err){ | |
if(!err){ | |
console.log('Post saved.'); | |
} | |
}); | |
} | |
function findPosts(amount){ | |
var Post = mongoose.model('Post'); | |
Post.find({).limit(amount).each(function(err,post){ | |
if(post!=null){ | |
Console.log(post.subject); | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment