2

我的查询是:

Collection::WhereIn('email',$email)->orWhereIn('mobile',$mobile)->get();

正在执行的 Mongo 查询是:

db.collection.find({"$and":[{"deleted_at":null},{"email":{"$in":["dfsdf@fsd.dfgf","sa$d.c"]}}],"$or":[{"mobile":{"$in":["39834787348","349430984390"]}}]},[])

没有得到正确的结果

实际上下面的 Mongo 查询给出了正确的结果,但是如何在 Laravel 中执行它。

db.collection.find({$or:[{"email":{$in:["dfsdf@fsd.dfgf","sa$d.c"]}},{"mobile":{$in:["9892230504"]}}]}).pretty()

我正在使用 Laravel jeneggers/mongodb 包。

4

1 回答 1

0

考虑文档Advanced Wheres中的示例,您可以在其中尝试:

DB::table('collection')
            ->whereIn('email', $email)
            ->orWhere(function($query)
            {
                $query->whereIn('mobile', $mobile);
            })
            ->get();

上面的查询将产生以下 SQL:

select * from collection 
where email in ('dfsdf@fsd.dfgf', 'sa$d.c') 
      or ( mobile in ('39834787348', '349430984390'))
于 2015-05-18T14:16:01.190 回答