node.js - 创建集合后如何设置“上限”?
问题描述
我试图capped
在我的 mongoose.Schema 中为我的集合设置一个参数,该参数最初不包括在内capped
。欢迎任何帮助。
我的架构:
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;
我收到以下错误:
Error: A non-capped collection exists with the name: users
To use this collection as a capped collection, please first convert it.
解决方案
好像您已经users
在数据库中创建了一个集合。因此,要将其转换为以下命令的上限运行mongoshell
或robomongo
db.runCommand( { convertToCapped: 'users', size: 1024 } )
推荐阅读
- javascript - 如何在 D3js 树中插入矢量 .svg 图像
- angular - Angular Matdialog 缺少后台和主题
- python-xarray - xarray.Dataset:在保持属性的同时更改坐标值?
- c++ - 错误:显示没有动态分配的链表(DISPLAY 不工作)
- python - 没有 id 的 Psycopg execute_values
- c++ - 如何使用 boost::asio::stream_socket_service 将代码移植到较新版本的 boost 和 asio?
- php - 使用一个 laravel 内核进行多个应用程序
- openedge - Progress4gl内部程序和函数的区别?
- python - Pandas 检查列中是否存在行并返回 True 或 False
- shell - 将位置参数作为变量传递给 awk