mongodb中的自动增量字段

时间:2016-06-01 05:04:25

标签: node.js mongodb mongoose mongoose-schema mongoose-plugins

我正在尝试在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

0 个答案:

没有答案