收藏
回答

数组command $.in 第二个参数提示不是数组是哪里出错了?

云数据库存在以下数据:

{"_id":"apple-1","category":"fruit","name":"apple","price":10.0,"cost":-22.0,"arrSupplier":["刘一","陈二","张三"],"proterties":{"content1":"string1","key":"key1","number1":1.0},"arrayObject":[{"objString":"objString1","objNumber":11.0},{"objNumber":12.0,"objString":"objString2"},{"objNumber":13.0,"objString":"objString3"}]}

{"_id":"orange-1","name":"orange","price":15.0,"category":"fruit","cost":-12.0,"arrSupplier":["张三","王五","赵六"],"properies":{"number1":12.0,"content1":"string2","key":"key2","array1":["array-2",12.0]},"arrayObject":[{"objectNumber":21.0,"objectString":"objectString21"},{"objectString":"objectString22","objectNumber":22.0}]}

测试代码:

db.collection('test').aggregate().project({

  var_arrSupplier:$.in(['张三','$arrSupplier']) 

}).end()

错误提示:

Error: FailedOperation, (Location40081) $in requires an array as a second argument, found: missing (9d088be4-734b-48ca-81cc-69bed569587f)

求助:

是我哪里做错了?$.in的第二个参数确实是数组啊.

请大家帮我一下.谢谢.

回答关注问题邀请回答
收藏

2 个回答

  • Mr.Zhao
    Mr.Zhao
    2021-11-21

    数据库一共只有这两条数据?

    2021-11-21
    有用 1
    回复 1
    • 方海山
      方海山
      2021-11-21
      谢谢你的提醒.感谢.
      2021-11-21
      回复
  • 方海山
    方海山
    2021-11-21

    谢谢你.我发现问题了.

    是因为不是所有的数据都有此字段.

    解决:

    我把所有的数据都添加该类型的字段.

    2021-11-21
    有用
    回复
登录 后发表内容