Mongo find by regex: return only matching string

前端 未结 2 1071
天命终不由人
天命终不由人 2021-01-14 15:13

My application has the following stack:

Sinatra on Ruby -> MongoMapper -> MongoDB

The application puts several entries in the database. In order to crosslink

2条回答
  •  广开言路
    2021-01-14 16:08

    I don't know if I understand.

    db.yourColl.aggregate([
    {
        $match:{"yourKey":{$regex:'[a-zA-Z0-9]', "$options" : "i"}}
    },
    {
        $group:{
            _id:null,
            tot:{$push:"$yourKey"}
        }
    }])
    

    If you don't want to have duplicate in totuse $addToSet

提交回复
热议问题