mongodb плагин автоматического увеличения mongoose nextCount not found
Я использую плагин mongoose-auto-increment, и я использую typcript nodejs, и я установил необходимые типизированные определения, но когда я пытаюсь получить следующий счетчик автоинкремента, я получаю это
Property 'nextCount' does not exist on type 'Model<Document>'
Моя схема из примера:
let bookSchema = new Schema({
author: { type: Number, ref: 'Author' },
title: String,
genre: String,
publishDate: Date
});
bookSchema.plugin(autoIncrement.plugin, 'Book');
var Book = connection.model('Book', bookSchema);
//// error here
Book.nextCount(function(err, count) {
});
мой tsconfig.json такой
{
"compilerOptions": {
"types" : ["node", "socket.io"],
"module": "commonjs",
"experimentalDecorators": true,
"target": "es2015",
"lib": ["es2015", "es2017", "dom"]
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
}
1 ответ
Просто используйте ObjectId
и установить _id
за каждое сообщение в чате перед сохранением пакета:
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
messages.forEach(message => {
message._id = message._id || ObjectId()
})
// call you method which save batches
saveBatch(messages)