Reputation: 435
I am attempting to set a capped
parameter to my collection within my mongoose.Schema that did not include capped
at first.
Any help welcome.
My Schema:
const mongoose = require('mongoose')
var Schema = mongoose.Schema;
var userSchema = new Schema({
name: { type: String, required: true },
email: { type: String },
password: { type: String },
isAdmin: {type: Boolean, default: false},
avatar: { type: String },
joinDate: { type: Date, default: Date.now() },
},{ autoCreate: true, capped : 1024})
userSchema.set('timestamps', true);
const Users = mongoose.model('Users', userSchema)
module.exports = Users;
I get following error:
Error: A non-capped collection exists with the name: users
To use this collection as a capped collection, please first convert it.
Upvotes: 1
Views: 296
Reputation: 46461
Seems like you have already created a users
collection in your database. So to convert it into a capped run below command either in mongoshell
or robomongo
db.runCommand( { convertToCapped: 'users', size: 1024 } )
Upvotes: 1