【发布时间】:2020-09-10 15:04:58
【问题描述】:
您好,我有一个小问题,我希望有人知道我该如何处理这个问题。
{
"isim": "This is topic - 2",
"resim": "anywhere2.png",
"ozellik": {
"detay": ["qv", "asv", "asd" , "vx"],
"bilgi": ["xc", "bv", "hjm" , "sax"]
}
},
{
"isim": "This is topic - 1",
"resim": "anywhere.png",
"ozellik": {
"detay": ["sa", "as", "de", "ed"],
"bilgi": ["bv", "cv", "asd", "dsa"]
}
}
这是我的数据库,我可以这样做: bilgi[2] 这样的
{ $project: {
_id: 0,
isim: 1,
boyut: { $arrayElemAt: ["$ozellik.bilgi", -2] },
}}
并且此代码返回以下行:
{
"isim": "This is topic - 2",
"boyut": "hjm"
},
{
"isim": "This is topic - 1",
"boyut": "asd"
}
这里是,我想知道“hjm”或“asd”的长度是多少
这对我不起作用:String field value length in array in mongoDB
我试试这个:
boyut: { $strLenCP : {$arrayElemAt: ["$ozellik.bilgi", -2]} },
node js 就是这么说的,Screenshot
MongoError: $strLenCP requires a string argument, found: missing
【问题讨论】:
-
您的最后一次尝试运行良好playground
-
该代码有什么问题? i.hizliresim.com/trfnqg.png