0

jenssegers 查询生成器存在以下问题(我是新用户):

print_r(DB::table($tablename)->where('_id',$_id)->select($table_structure_record['field'])->get());

尽管在 select 语句中只指定了一列,但返回给我的列不止一列:

Array ( [0] => Array ( [_id] => MongoDB\BSON\ObjectID Object ( [oid] => 5780b81d93f7fb0e00d0f252 ) [collection] => structure ) )

我的预期结果只是 ([collection] => structure) ,我不明白为什么我还会得到“[_id] => MongoDB\BSON\ObjectID Object ([oid] => 5780b81d93f7fb0e00d0f252 )”

有人能帮我吗 ?尽管进行了多次搜索,但似乎 select 语句应该只返回指定的列,而不是任何其他列!

4

1 回答 1

1

MongoDb 始终返回 _id 字段,除非您在发出请求时明确将其设置为不(MongoDb 限制从查询文档返回的字段)。

您可以尝试改用项目。然后它将是这样的:

DB::table($tablename)->where('_id',$_id)->project([$table_structure_record['field'] => 1, "_id" => 0])->get());
于 2016-09-22T13:58:28.437 回答