nodejs向mongodb中插入数据后,在mongodb shell中查不到啊???
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://127.0.0.1:27017/local');
...
var mongooseSchema = new mongoose.Schema({
username: { type: String, default: '匿名用户' },
title: { type: String },
content: { type: String },
time: { type: Date, default: Date.now },
age: { type: Number }
});
var mongooseModel = db.model('user', mongooseSchema);
function mongooseTest(req, res, next)
{
var doc = { username: 'lx', title: 'iii', content: 'lx' };
var mongooseEntity = new mongooseModel(doc);
//mongooseEntity.save(function (error) {
// if (error) {
// console.log(error);
// } else {
// console.log('saved OK!');
// }
// //
// //db.close();
//});
mongooseModel.find({ username: 'lx' }, function (error,result) {
if (error) {
console.log(error);
} else {
console.log(result);
}
// 关闭数据库链接
//db.close();
});
next();
}
\n```
数据已经插入了,控制台都能输出查询结果有两条。
但是在shell中怎么查呢?
我输入
use local
db.user.find()
没结果,急死人啦~~~~~
请问哪里不对啊