【发布时间】:2017-11-30 02:24:52
【问题描述】:
在 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") 不是字符串,这就是上述代码不起作用的原因。反正我不确定。 但没有任何效果。我该怎么做。
【问题讨论】:
-
MasterAffiliateProductMappingMongo::where('common_id', ObjectId("5911af8209ed4456d069b1d1"))当然。而且我认为您实际上应该从MongoDB\BSON\ObjectId 拉入ObjectId。 -
老兄,这正是我给你 BSON 库函数链接的原因,你需要要导入。
-
@NeilLunn 哦....酷。 :) 谢谢
标签: mongodb laravel-5 eloquent where database