문제

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