我正在尝试从mongodb shell查询我的数据库以检索所有条目,但是我的find()方法没有返回任何内容。
这是我使用的mongoose模型:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ArticleSchema = new Schema({
title: String,
content: String,
author: { type: String, default: 'Vlad'},
postDate: { type: Date, default: Date.now }
});
ArticleSchema.methods.formatTitle = function() {
var link = this.title.replace(/\s/g, '-');
return '/article/' + link;
};
ArticleSchema.methods.snapshot = function() {
var snapshot = this.content.substring(0, 500);
return snapshot;
};
module.exports = mongoose.model('Article', ArticleSchema);
当在浏览器中加载我的Express.js应用程序时,使用API添加的所有文章都可以正常显示。但是,我只想进入mongo shell并进行查询。我已经使用了以下查询:
// blog is the database name (mongodb://localhost:27017/blog)
db.blog.find()
我得到的返回值是空字符串,也就是控制台中的换行符。
db.getCollectionNames()
来查看单个数据库中存在哪些内容。 - WiredPrairie