您好:我很难在线查找如何使用 mongoose 和 node.js 执行简单的数据库连接、模式创建和基本 CRUD。现在我有以下代码,但收到错误:
“类型错误:对象不是函数
在 Schema.CALL_NON_FUNCTION_AS_CONSTRUCTOR(本机)..”
// Launch express and server
var express = require('express');
var app = express.createServer();
//connect to DB
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/napkin_0.1');
// Define Model
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
User = new Schema({
'title': { type: String, index: true },
'data': String,
'tags': [String],
'user_id': ObjectId
});
//Define Collection
mongoose.model('Document', User);
var user = new User();
user.title = "TEST TITLE";
user.save();
//Launch Server
app.listen(3002);