Created
September 25, 2011 17:52
-
-
Save toritori0318/1240896 to your computer and use it in GitHub Desktop.
mongooseで入れたデータがmongodbのコマンドラインから見れない件
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
| #### node.js | |
| var mongoose = require('mongoose'); | |
| mongoose.connect('mongodb://localhost/counterdb'); | |
| var Schema = mongoose.Schema; | |
| var CounterSchema = new Schema({ | |
| count: Number | |
| }); | |
| mongoose.model('Counter', CounterSchema); | |
| var Counter = mongoose.model('Counter'); | |
| Counter.findOne({}, function(err, rec) { | |
| if(err || rec == null) { | |
| var counter = new Counter(); | |
| rec = counter; | |
| rec.count = 1; | |
| } else { | |
| rec.count = rec.count + 1; | |
| } | |
| rec.save(function(err) { | |
| if (err) { | |
| console.error(err); | |
| return; | |
| } | |
| }); | |
| console.log(rec); | |
| }); | |
| $ node test.js | |
| { count: 1, _id: xxxxxxxxxxxxxxxxxxxxxxxxx } | |
| #### mongo cli | |
| $ mongo counterdb | |
| > db.Counter.find() | |
| > | |
| (なんで?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment