How to say… match when field is a number… in mongodb?

后端 未结 8 540
误落风尘
误落风尘 2021-02-04 07:41

So I have a field called \'city\' in my results...the results are corrupted, some times it\'s an actual name, sometimes it\'s a number. The following code displays all the recor

8条回答
  •  独厮守ぢ
    2021-02-04 08:18

    You can also use an in command

    db.zips.aggregate([     
        {
            $project: {
                first_char: { 
                    $substr : ["$city",0,1]
                }, 
                "_id":"$_id"
            } 
        }, 
        {
            $match: {
                first_char: { 
                    $in: ["0","1","2","3","4","5","6","7","8","9"] 
                }
            }
        }
    ]) 
    

提交回复
热议问题