selecting _id doesn't work with unselected props #954

Closed
kof opened this Issue Jun 7, 2012 · 7 comments

Comments

Projects
None yet
2 participants

kof commented Jun 7, 2012

Usecase

I use query.fields('_id'), while some other filelds are unselected in the schema.

Problem

  1. It works fine if selecting any other props, but not _id - query will contain just the selected fields in the query. But if selecting '_id', it will be added to other unselected fields, which will end up with mongo error: "You cannot currently mix including and excluding fields. Contact us if this is an issue."
  2. The error passed to the callback from mongoose is not an Error instance, but a string.

mongoose 2.6.4

Collaborator

aheckmann commented Jun 7, 2012

can you provide code reproducing the issue?

kof commented Jun 7, 2012

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var assert = require('assert')
mongoose.connect('localhost', 'testing_select');
var schema = new Schema({
  name: String,
  nick: {
    type: String,
    select: false
  }
}, {strict: true});

var A = mongoose.model('A', schema);

mongoose.connection.on('open', function () {
  A
    .find()
    .select('_id')
    .exec(function (err, doc) {
      console.error(err);
      console.error(typeof err);
      mongoose.connection.db.dropDatabase(function () {
        mongoose.connection.close();
      });
    });
});

aheckmann closed this in 4286fa2 Jun 7, 2012

Collaborator

aheckmann commented Jun 7, 2012

fixed in 2.x and master. thanks for the report!

kof commented Jun 7, 2012

what about typeof err == 'string' ?

Collaborator

aheckmann commented Jun 7, 2012

done as well.

Collaborator

aheckmann commented Jun 7, 2012

kof commented Jun 7, 2012

Thanks!

@aheckmann aheckmann added a commit to aheckmann/mongoose that referenced this issue Jun 9, 2012

@aheckmann aheckmann fixed; selection of _id with schema deselection
closes #954
03bed09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment