1
如何編寫不喜歡在laravel用mongodb的?我發現這一個,但不知道如何使用它在laravel -哪裏不喜歡在laravel mongodb
db.tbl_users.find({ first_name: { $not: /^M.*/ } })
請幫助,謝謝。
如何編寫不喜歡在laravel用mongodb的?我發現這一個,但不知道如何使用它在laravel -哪裏不喜歡在laravel mongodb
db.tbl_users.find({ first_name: { $not: /^M.*/ } })
請幫助,謝謝。
regex
的操作者選擇其中的值匹配指定正則表達式的文檔。
User::where('first_name', 'regex', new \MongoDB\BSON\Regex("/^M.*/"))->get();
注意:您還可以使用Laravel regexp
操作。這些更靈活一些,並會自動將您的正則表達式字符串轉換爲MongoDB\BSON\Regex
對象。
User::where('first_name', 'regexp', '/^M.*/'))->get();
和逆:
User::where('first_name', 'not regexp', '/^M.*/'))->get();
謝謝@chridam,大的幫助。 –