简体   繁体   English

猫鼬问题:未定义架构

[英]Mongoose problem: schema not defined

Hey guys, I've been trying to play with mongoose & node, but I have some problem regarding even the simplest run... I have this code: 大家好,我一直在尝试使用猫鼬和node,但是即使是最简单的运行,我也有一些问题...我有以下代码:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var db = mongoose.connect('mongodb://localhost/db');

var User = new Schema({
  email: {
    type: String,
    index: { unique: true }
  },
  name: String,
  lastseen: Date,
  isonline: Boolean,
  hashed_password: String,
  salt: String
});

mongoose.model('User', User);

var User = db.model('User');

var u = new User();
u.name = 'Foo';

u.save(function() {
    User.find().all(function(arr) {
        console.log(arr);
        console.log('length='+arr.length);
    });
});

Which should run, since it's an example code... but I have this error: 应该运行,因为它是示例代码...但是我遇到了这个错误:

node.js:181
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
ReferenceError: Schema is not defined
    at Object.<anonymous> (myfile.js:12:1)
    at Module._compile (module.js:420:26)
    at Object..js (module.js:426:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at Array.<anonymous> (module.js:439:10)
    at EventEmitter._tickCallback (node.js:173:26)

Does anyone of you know what's wrong with this? 你们当中有人知道这是怎么回事吗? Thanks. 谢谢。

Which version of mongoose are you using? 您正在使用哪个版本的猫鼬?

I ran into similar problems with mongoose < 1.1.0 which updating cured. 我遇到了猫鼬<1.1.0的类似问题,该问题已得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 JSON 文件创建 mongoose 架构时出现问题 - Problem creating a mongoose schema from a JSON file 如何获取在另一个模型中定义的猫鼬数据库的架构 - How to get Schema of mongoose database which defined in another model Mongoose忽略对象的一部分,除非定义为Schema.Types.Mixed - Mongoose ignoring part of object unless defined as Schema.Types.Mixed ZCCADCDEDB567ABAE643E15DCF0974E503Z 当路由包含在不同的文件中时架构未定义 - Mongoose Schema Not Defined when Route is included in different file 模式中的猫鼬模式 - Mongoose schema within schema 有没有办法在mongoose集合中动态插入/添加未定义为模式一部分的新字段? - Is there a way to dynamically insert/add new fields that are not defined as part of the schema in a mongoose collection? mongoose 数组以错误的顺序保存或如果定义了数组的架构,则会出现错误“转换为字符串失败的值” - mongoose array saved in wrong order or got error 'Cast to string failed for value' if schema for array is defined 如何在 model 中检索完整列表时调用 mongoose 模式中定义的方法? - How to call method defined in a mongoose schema while retriving complete list in a model? 如何在猫鼬模式中设置与已定义类型不同的属性类型? - How do I set a different type of property in mongoose schema from the defined type? Mongoose 架构内的相同架构 - Same Schema within Schema in Mongoose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM