Node.js Mongoose Model.find().select()如果select是空字符串,返回什么?

Node.js Mongoose Model.find().select()如果select是空字符串,返回什么?,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,假设我们使用的是一个简单的模式: const phoneRegex = require('./phoneRegex'); const Schema = require('mongoose').Schema; const PersonSchema = new Schema({ firstName: String, lastName: String, phone: { type: String, regex: phoneRegex, }, Address: {

假设我们使用的是一个简单的模式:

const phoneRegex = require('./phoneRegex');
const Schema = require('mongoose').Schema;
const PersonSchema = new Schema({
  firstName: String,
  lastName: String,
  phone: {
    type: String,
    regex: phoneRegex,
  },
  Address: {
    street1: String,
    street2: String,
    city: String,
    state: String,
    zip: String,
  }
});

module.exports = Person = require('mongoose').model('Person', PersonSchema);
我想预先调用mongoose来查找人员列表,但我希望可以选择限制从数据库返回的内容。我知道我可以使用模型的select函数,但是当您提供一个空字符串时会发生什么呢?i、 e.Person.findoptions.select

我的预定义函数如下所示:

//sample options object.
const options = {
  firstName: {
    $regex: '^John',
    $options: 'i',
  },
};
const Person = require('./person');
const fetchAll = (Options, select = '') => {
  return Person.find(Options).select(select);
};
我知道我想传递属性名来选择返回,但是空的选择字符串是否与选择无相同?

在通读之后,除了_id字段之外,所有字段都将被忽略,因为默认情况下包括该字段。你是说什么都不包括,其他的都不包括


我目前没有猫鼬设置来测试这一点,所以这更像是一个有根据的猜测。

这是可以理解的,我认为这是沿着这些思路进行的。非常感谢。