不支持的投影选项:numberOfPersons: { description: 1 }

HerbertoPæga1778

它可以建模

const tourSchema = new Schema({
  image: { type: String, required: true, trim: true },
  numberOfPersons: {
    name: { type: String, required: true, trim: true },
    description: { type: String, required: true, trim: true },
  },
})

const tourModel = mongoose.model("Tour", tourSchema);

当我使用选择

const doc = await tourModel.find(
        {},
        {
          image: 1,
          numberOfPersons: {
            description: 1,
          },
        }
      );

我得到错误

不支持的投影选项:numberOfPersons: { description: 1 }

是什么原因 ?。

毗湿奴

您可以使用点表示法来选择 JSON 对象中的字段

const doc = await tourModel.find(
  {},
  {
    'image': 1,
    'numberOfPersons.description': 1,
  }
);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

OperationFailure 不支持的投影选项:endingDate

MongoError:不支持的投影选项 - 使用 $elemMatch 时

MongoDB:“不支持的投影选项:pop:{$ gt:0.0}”(调试)

为什么在双符号SHA2和SHA1上signtool.exe不支持/ as选项

Xamarin UI测试“ 1不支持的代码页。”

where 条件不支持超过 1 个条件

不支持参考“ r1”(对组功能的参考)

Windows不支持mc.cores> 1

curl:(1)libcurl不支持或禁用协议https

不支持选项[useMongoClient]

不支持选项[methodName]

不支持选项“useFindAndModify”

Mongodb:不支持选项[...]

errmsg:“不支持的投影选项:$ push:{...}”,代码:2,codeName:“ BadValue”}

fsck错误:当前,仅支持1或2个FAT,不支持34

socat 不支持 sourceport 选项

接收端不支持推送选项

org.osgi.framework.BundleException:不支持的“Bundle-ManifestVersion”值:1

不支持嵌套查询。Operation1 ='UnionAll'Operation2 ='MultiStreamNest'

ZipArchive文件中的Json不支持ISO-8859-1格式

致命:git是在不支持git-add--interactive的情况下构建的(NO_PERL = 1)

Lambda-cn-north-1区域不支持EnvironmentVariablesFeature

cordova-plugin-geolocation导致不支持1k的设备

'TruncateTime(System.Nullable`1 [System.DateTime])'不支持对SQL的转换。

后端不支持 Django qs1.difference(qs2, qs3)

TensorFlow 1.x:TypeError:/:不支持的操作数类型:'NoneType'和'int'

brainpool320r1 Java卡不支持椭圆曲线吗?

不支持build.phonegap插件:cordova-plugin-whitelist @ 1

git 2.20.1.windows.1不支持http.sslverify = false