我正在尝试在 mongodb 中创建一个自动增量字段,但出现错误。我是 mongodb 的新手,所以有人可以帮我解决这个错误吗?我的代码是:
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var multer = require('multer');
var app=express();
var autoIncrement = require("mongodb-autoincrement");
/*autoIncrement.setDefaults({
collection:' carousel2', // collection name for counters, default: counters
field: 'chieldId', // auto increment field name, default: _id
step:'1' // auto increment step
});*/
var MongoClient = require('mongodb').MongoClient;
var connection=mongoose.createConnection('mongodb://localhost/db');
var Settings = new Schema({
nextSeqNumber: { type: Number, default: 1 }
});
var schema = new mongoose.Schema (
{ img:{ data: Buffer, contentType: String },
chieldId:{type:Number,default:1}
}
);
schema.plugin(autoIncrement.mongoosePlugin);
得到的错误是
fn(this, opts);
^
TypeError: fn is not a function
at Schema.plugin (F:\backup\eni-master\eni-master\src\public\api\node_modules\mongoose\lib\schema.js:908:3)
at Object.<anonymous> (F:\backup\eni-master\eni-master\src\public\api\index.js:23:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3