2

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);
}
R01010010
  • 5,670
  • 11
  • 47
  • 77
  • You're indexing each field individually in that schema, so that doesn't align with "a couple indexes". What indexes are you trying to create? Also, see [here](http://stackoverflow.com/a/12453041/1259510) for some info on debugging this. – JohnnyHK May 12 '16 at 13:01

0 Answers0