When I run this code in my node script, for some reason when I check the db using db.test.find(), nothing shows up. Any clues?
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/test');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
UserSchema = new Schema({
'title': { type: String, index: true },
});
var User = mongoose.model('user', UserSchema);
var user = new User();
user.title = "TEST TITLE";
user.save();
Thanks guys
You need to use the database 'test' in the console. Why test? because you're telling it to in this line:
var db = mongoose.connect('mongodb://localhost/test');
Console:
> use test
Also with mongoose; it pluralizes the collection, so its saving it into "users".
> db.users.find()