我正在尝试从 mongodb shell 查询我的数据库以检索所有条目。不过,我的 find() 方法什么也没返回。
这是我正在使用的猫鼬模型:
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()
我得到一个空字符串作为回报,基本上是控制台中的一个新行。