为什么我不能使用模式重命名集合?
Why can't I rename the collection using the Schema?
我想重命名我的架构中的集合,但 mongodb 继续使用旧名称。
我已经 运行 我的代码,架构名称设置为“__filters”,但现在我需要将名称更改为“__filter”。 (不是复数)
当我创建过滤器时,mongodb 创建了一个“__filters”集合
这就是我设置原始架构的方式,注意复数 'filters'
// create the schema
const FiltersSchema = new Schema({
test: {type: String, required: true},
})
module.exports = Filters = mongoose.model('__filters', FiltersSchema)
现在我想将集合名称设为单数“__filter”。这是我要使用的新架构:注意:现在全部为单数
// create the schema
const FilterSchema = new Schema({
test: {type: String, required: true},
})
module.exports = Filter = mongoose.model('__filter', FilterSchema)
这是我正在使用的代码:
const Filter = require('./Filter');
createFilter = ( test ) => {
return new Promise((resolve, reject) =>{
var errors = {};
Filter.findOne( {test:test} )
.then(found => {
if(found) {
errors.err = {'inUse':'already created'};
console.log(errors);
reject(errors);
} else {
const newFilter = new Filter({
test: test
});
newFilter.save()
.then(f => {
if(debugThis){
console.log(' ');
console.log(' created ' + JSON.stringify(f));
console.log(' ');
}
resolve(f);
})
.catch(err => {
errors.exception = {'save':err};
console.log(errors);
reject(errors);
});
}
})
.catch(err => {
errors.exception = {'findOne':err};
reject(errors);
})
});
};
这几乎就像某个地方有一些缓存在保留旧的 'filters' 模式。
有什么我需要清除的吗?
这个我也试过了,也没用
let dbc = mongoose.connection.db;
dbc.collection('filters').rename('filter')
.then()
.catch(err =>{});
我关闭了 DevStudio 并重新启动了它。
我在 MongoDB
中创建了一个新数据库
我重新启动了 MongoDB 服务器服务
似乎无法将“__filters”重置为“__filter”
无奈之下,我从架构中删除了 _filter,但它崩溃了,并吐出:
TypeError: Cannot read property 'toLowerCase' of undefined
at pluralize
(\node_modules\mongoose-legacy-pluralize\index.js:85:13)
mongoose 会自动将名字设为复数吗??
好吧让我失望橄榄油...猫鼬使东西复数...他们 'nice' 如何做到这一点...我不想要复数名称...
天哪...我简直不敢相信...我的 4 个小时浪费在这些愚蠢的事情上:
Why does mongoose always add an s to the end of my collection name
我想重命名我的架构中的集合,但 mongodb 继续使用旧名称。
我已经 运行 我的代码,架构名称设置为“__filters”,但现在我需要将名称更改为“__filter”。 (不是复数)
当我创建过滤器时,mongodb 创建了一个“__filters”集合
这就是我设置原始架构的方式,注意复数 'filters'
// create the schema
const FiltersSchema = new Schema({
test: {type: String, required: true},
})
module.exports = Filters = mongoose.model('__filters', FiltersSchema)
现在我想将集合名称设为单数“__filter”。这是我要使用的新架构:注意:现在全部为单数
// create the schema
const FilterSchema = new Schema({
test: {type: String, required: true},
})
module.exports = Filter = mongoose.model('__filter', FilterSchema)
这是我正在使用的代码:
const Filter = require('./Filter');
createFilter = ( test ) => {
return new Promise((resolve, reject) =>{
var errors = {};
Filter.findOne( {test:test} )
.then(found => {
if(found) {
errors.err = {'inUse':'already created'};
console.log(errors);
reject(errors);
} else {
const newFilter = new Filter({
test: test
});
newFilter.save()
.then(f => {
if(debugThis){
console.log(' ');
console.log(' created ' + JSON.stringify(f));
console.log(' ');
}
resolve(f);
})
.catch(err => {
errors.exception = {'save':err};
console.log(errors);
reject(errors);
});
}
})
.catch(err => {
errors.exception = {'findOne':err};
reject(errors);
})
});
};
这几乎就像某个地方有一些缓存在保留旧的 'filters' 模式。
有什么我需要清除的吗?
这个我也试过了,也没用
let dbc = mongoose.connection.db;
dbc.collection('filters').rename('filter')
.then()
.catch(err =>{});
我关闭了 DevStudio 并重新启动了它。
我在 MongoDB
中创建了一个新数据库我重新启动了 MongoDB 服务器服务
似乎无法将“__filters”重置为“__filter”
无奈之下,我从架构中删除了 _filter,但它崩溃了,并吐出:
TypeError: Cannot read property 'toLowerCase' of undefined
at pluralize
(\node_modules\mongoose-legacy-pluralize\index.js:85:13)
mongoose 会自动将名字设为复数吗??
好吧让我失望橄榄油...猫鼬使东西复数...他们 'nice' 如何做到这一点...我不想要复数名称...
天哪...我简直不敢相信...我的 4 个小时浪费在这些愚蠢的事情上:
Why does mongoose always add an s to the end of my collection name