Mongoose 说我有 46 条记录,mongoDB 说我有 0 条记录?
以下测试脚本表示我有 46 条记录:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var DealSchema = new Schema({
title : String,
});
var Deal = mongoose.model('Deal', DealSchema);
mongoose.connect('mongodb://localhost/dealsite');
mongoose.connection.on("open", function(){
console.log("Mongoose connected");
Deal.count({}, function( err, count){
console.log( "Records:", count );
})
});
输出:
$ node testmongo.js
Mongoose connected
Records: 46
如果我尝试使用 mongo shell 读取数据线,则会得到不同的结果:
$ mongo localhost/dealsite
MongoDB shell version: 1.4.4
url: localhost/dealsite
connecting to: localhost/dealsite
type "exit" to exit
type "help" for help
> db.dealsite.count()
0
> db.dealsite.Deal.count()
0
我的记录隐藏在哪里?
The following test script says I have 46 records:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var DealSchema = new Schema({
title : String,
});
var Deal = mongoose.model('Deal', DealSchema);
mongoose.connect('mongodb://localhost/dealsite');
mongoose.connection.on("open", function(){
console.log("Mongoose connected");
Deal.count({}, function( err, count){
console.log( "Records:", count );
})
});
output:
$ node testmongo.js
Mongoose connected
Records: 46
While if I try to read the cords using the mongo shell I get a different story:
$ mongo localhost/dealsite
MongoDB shell version: 1.4.4
url: localhost/dealsite
connecting to: localhost/dealsite
type "exit" to exit
type "help" for help
> db.dealsite.count()
0
> db.dealsite.Deal.count()
0
Where are my records hiding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 MongoDB 中,尝试:
如果您创建一个名为“Deal”的 Mongoose 模型,它将创建并使用名为“deal”的 MongoDB 集合。
In MongoDB, try:
If you create a Mongoose model called "Deal", it will create and use a MongoDB collection called "deals".
你错过了声明:
在做之前
you missed the statement :
before doing