在MongoDb中,我的文档名为" common_id"。我只想获取特定common_id的所有文档。
这就是common_id字段的样子。
"common_id" : ObjectId("5911af8209ed4456d069b1d1"),
我试过了,
$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', '=', 'true')
->get();
此,
$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', '=', 'ObjectId("5911af8209ed4456d069b1d1")')
->get();
这个,
MasterAffiliateProductMappingMongo::where('common_id', '=', ObjectId("5911af8209ed4456d069b1d1"))
->get();
也尝试了这个,
$bestAmongAffiliates = MasterAffiliateProductMappingMongo::where('common_id', new MongoDB\BSON\ObjectID('5911af8209ed4456d069b1d1'));
我认为问题在于 - ObjectId(" 5911af8209ed4456d069b1d1")不是一个字符串,这就是上述代码无法正常工作的原因。无论如何我不确定。 但没有任何作用。我怎么能这样做。
答案 0 :(得分:0)
::where('common_id', '5911af8209ed4456d069b1d1')->get()
如果您使用的是Jenssegers Laravel MongoDB,应该可以使用。
检查string
和字符串是否为ctype_xdigit
,然后在查询构建器中将其转换为对象