node.js - MongoDb 聚合全文搜索不返回 id 字段
问题描述
我在我的 Mongo 数据库中实现了全文搜索。当我尝试使用聚合搜索我的索引时,结果很好,但缺少 id。
models.Piece.aggregate([
{
$searchBeta: {
"index": "search-piece",
"search": {
"query": search,
"path": ["name", "styles"],
"phrase": { prefix: true },
},
},
},
{
$skip: offset,
},
{
$limit: limit,
},
]);
解决方案
我解决问题。问题来自 graphql 和 mongodb 聚合。我必须为 id 字段编写特定的解析。
Piece: {
id: (parent, args, { models }) => parent._id,
},
推荐阅读
- django - 如何在 django 的模型管理器上动态交换默认数据库?
- jquery - 我想以条带量显示 jquery 变量数据
- node.js - ReferenceError:在 Angular 中使用 jsPDF 时未定义窗口
- image - Flutter如何处理框内固定大小的图像?
- html5-audio - 暂停时阻止 icecast 玩家落后
- bazel - 如何使用 bazel 为 android 构建 cc_test
- selenium-webdriver - Appium 本地测试
- javascript - 云函数 -> 比较时间戳
- vue.js - 获取所有输入值 - Vuejs
- ruby - iTerm2 设置为登录 Shell,RVM 仍然报错