Jenssegers / select('column') returns 列比 select 中指定的列多

Jenssegers / select('column') returns more columns than the one specified in the select

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

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

return给我不止一列,尽管在 select 语句中只指定了一列:

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

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

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

MongoDb 始终 returns _id 字段,除非您在发出请求时特别将其设置为不设置 (MongoDb Limit Fields to Return from Query Documentation).

您可以尝试使用项目 instead.Then 它将是这样的:

DB::table($tablename)->where('_id',$_id)->project([$table_structure_record['field'] => 1, "_id" => 0])->get());