質問

I have tried to search around for clues but didn't find any. Please let me ask a question about reverse search for mongodb.

I have a collection that contain a phone prefix, let say bellow.

{"prefix":"1234"}

and i am trying to make it hit with value like 12341111 or 12342222 ... in MySQL i can do it with below SQL.

SELECT * from phoneprefix where ‘12341111’ like concat(prefix,’%’)

Is there anyway to make it possible at mongodb ?

Thanks for reading my post and please have a nice day !

役に立ちましたか?

解決

The only way I can see to do this is to use the performance-challenged $where operator:

db.phoneprefix.find({$where: function() {
    return (new RegExp('^' + this.prefix)).test('12341111'); 
}});

他のヒント

You could use $regex in MongoDB.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top