/ / एक नया संग्रह फेंकने त्रुटि - node.js, mongoose बनाना

एक नया संग्रह फेंकने त्रुटि - 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;