对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

查找文档

要从集合中检索单个文档,您可以使用 Model::where() 等方法或 DB 门面中的方法匹配文档,然后调用 first() 方法返回一个文档。

If multiple documents match the query filter, first() returns the first matching document according to the documents' natural order in the database or according to the sort order that you can specify by using the orderBy() method.

提示

要学习;了解使用 Laravel 集成检索文档的其他方法,请参阅读取操作指南。

从以下 Eloquent 和 Query Builder 标签页中选择,查看使用每个相应查询语法的同一操作的用法示例:

此示例将执行以下动作:

  • 使用Movie Eloquent 模型表示sample_mflix数据库中的movies集合

  • 从movies集合中检索与查询筛选器匹配的文档

  • 打印检索到的文档

该示例在Movie模型上调用以下方法:

  • where():匹配其中 directors字段的值包含 "Rob Reiner" 的文档

  • orderBy():按 _id 值升序对匹配的文档进行排序

  • first():仅检索第一个匹配的文档

$movie = Movie::where('directors', 'Rob Reiner')
->orderBy('id')
->first();
echo $movie->toJson();

要了解如何编辑 Laravel 应用程序以运行用法示例,请参阅用法示例登录页面。

给本页内容打分