简体   繁体   English

MongoDb Laravel where子句

[英]MongoDb Laravel where clause

In MongoDb i have documents with a field named "common_id". 在MongoDb中,我有带有名为“ common_id”的字段的文档。 I just want to fetch all documents of a particular common_id. 我只想获取特定common_id的所有文档。

This is how the common_id field looks like. 这就是common_id字段的样子。

"common_id" : ObjectId("5911af8209ed4456d069b1d1"),

I have tried this, 我已经试过了

$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', '=', 'true')
->get();

this, 这个,

$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', '=', 'ObjectId("5911af8209ed4456d069b1d1")')
->get();

and this, 和这个,

MasterAffiliateProductMappingMongo::where('common_id', '=', ObjectId("5911af8209ed4456d069b1d1"))
    ->get();

also tried this, 也尝试过

$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', new MongoDB\BSON\ObjectID('5911af8209ed4456d069b1d1'));

I think the problem is that - ObjectId("5911af8209ed4456d069b1d1") is not a string thats why the above codes are not working. 我认为问题在于-ObjectId(“ 5911af8209ed4456d069b1d1”)不是字符串,因此上述代码无法正常工作。 Anyway am not sure. 反正不确定。 But nothing works. 但是什么都行不通。 How can i do this. 我怎样才能做到这一点。

::where('common_id', '5911af8209ed4456d069b1d1')->get()

should work if you are using Jenssegers Laravel MongoDB. 如果使用的是Jenssegers Laravel MongoDB,则应该可以使用。

Checks if it string and string is ctype_xdigit then converts as object in the query builder 检查string和字符串是否为ctype_xdigit然后在查询生成器ctype_xdigit其转换为对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM