Mongoose is having a weird behaviour.
In scheme I have a couple of indexes, but sometimes it indexes all fields and other times it indexes just _id
. It never makes the index as they are in the scheme. Other schemes are working nice, but this one in particular is giving me problems. Maybe is because it has like 80 fields?
My env is mongodb v2.4.12, node v0.10.40, mongoose npm package v4.0.0
Here is the schema (I took out some fields for clarity):
'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);
}