猫鼬有一种奇怪的行为。
在方案中我有几个索引,但有时它会索引所有字段,有时它只会索引_id
。它永远不会像在计划中那样制作索引。其他方案工作得很好,但这个方案特别给我带来了麻烦。也许是因为它有80个领域?
我的环境是mongodb v2.4.12,节点v0.10.40,mongoose npm包v4.0.0
这是架构(为了清楚起见,我拿出了一些字段):
'use strict';
var log = require('../../../../lib/logging')(module.id),
config = require('../../../../production.config'),
me = module.exports = {
name: 'natstransactions',
model: {
originType: { // postback or import
type: String,
index: true,
unique: false,
required: true
},
type: {
type: String,
index: true,
unique: false,
required: true
},
memberid: {
type: Number,
index: false,
unique: false,
required: false
},
//transaction: {
transaction_id: {
type: Number,
index: true,
unique: true,
required: false,
trim: false,
sparse: true // This makes the transaction to be unique only if not null, so there can be more than one document with null as transaction_id
},
post_time: {
type: Date,
index: false,
unique: false,
required: false
},
post_type: {
type: String,
index: false,
unique: false,
required: false
}
},
virtual: function(schema) {
},
postInit: function(schema) {
// schema.plugin(random, {path: 'r'});
schema.set('toObject', {getters: true, virtuals: true});
schema.set('toJSON', {getters: true, virtuals: true});
}
};
if (config.debug) {
inspect(me.name + ' Schema', me);
}