nodejs向mongodb中插入数据后,在mongodb shell中查不到啊???
发布于 8 年前 作者 lx1412 4586 次浏览 来自 问答
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()
没结果,急死人啦~~~~~
请问哪里不对啊
3 回复

试试

db.users.find()

<3

看api去 自豪地采用 CNodeJS ionic

终端或cmd 下试试

回到顶部