Mongoose がサポートするモデルのインスタンスを保存する際に助けが必要です: エンティティを保存すると、次のエラーがスローされます:
node.js:134
00:27:16 web.1 | throw e; // process.nextTick error, or 'error' event on first tick
00:27:16 web.1 | ^
00:27:16 web.1 | TypeError: Cannot call method 'decodeInt' of undefined
00:27:16 web.1 | at model.<anonymous> (.../node_modules/mongoose-types/lib/plugins/useTimestamps.js:13:37)
00:27:16 web.1 | at VirtualType.applyGetters (.../node_modules/mongoose/lib/virtualtype.js:53:25)
00:27:16 web.1 | at model.get (...
モデル定義は
var mongooseTypes = require("mongoose-types"), useTimestamps = mongooseTypes.useTimestamps;
mongooseTypes.loadTypes(mongoose);
var Url = mongoose.SchemaTypes.Url;
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var TextSnippetSchema = new mongoose.Schema({
text_id : ObjectId
, text : String
, context : String
, url : Url
, position : String
});
TextSnippetSchema.plugin(useTimestamps);
var TextSnippet = mongoose.model('TextSnippet',TextSnippetSchema);
新しいエンティティを作成して保存するコードは次のようになります。
var instance = new TextSnippet();
instance.text= req.query["text"];
instance.context= req.query["ctx"];
instance.url = req.query["url"];
instance.position= "";
console.log(JSON.stringify(instance));
instance.save(function (err) {
console.log(err);
});
私の理解では、「decodeInt」が必要なプロパティはありませんが、エンティティを保存することはできません。
オブジェクトの永続性を機能させるのを手伝ってくれませんか?