/ / Създаване на нова грешка при хвърляне на колекция - node.js, мангуста

Създаване на нова грешка при хвърляне на колекции - node.js, mongoose

По-долу е грешката при получаване на нова колекция с помощта на мангуста.

  D:Workspacenode-2012-20nodenode_modulesmongooselibindex.js:191
throw new Error("Schema hasn"t been registered for model "" + name + ""
^
Error: Schema hasn"t been registered for model "testDocAccessModel".
Use mongoose.model(name, schema)
at Mongoose.model (D:Workspacenode-2012-20nodenode_modulesmongooselibindex.js:191)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)

По-долу е кодът

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

exports.TestDocumentAccessSchema = new Schema({
Id: { type: Schema.ObjectId },
parentId: { type: Schema.ObjectId },
userId: { type : String },
userName: { type : String },
});

var testDocAccessModel = mongoose.model("TestDocumentAccess", exports.TestDocumentAccessSchema);

Има ли улики?

Отговори:

0 за отговор № 1

Просто променете кода си по този начин и ме уведомете дали беше полезно

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

var TestDocumentAccessSchema = new Schema({
Id: { type: Schema.ObjectId },
parentId: { type: Schema.ObjectId },
userId: { type : String },
userName: { type : String },
});

var testDocAccessModel = mongoose.model("TestDocumentAccess",TestDocumentAccessSchema);
exports.TestDocumentAccessSchema = TestDocumentAccessSchema;