javascript - 猫鼬查询的行为方式很奇怪
问题描述
我正在使用带有 mongoose 的 MongoDB 作为我的 NodeJS 项目的 ORM 库。这里我放了同一个查询的两个版本,问题是 NoSqlBooster 版本正确返回值,而 mongoose 版本返回空数组,请找到查询的两个版本。
NoSQLBooster 版本:
db.users.find({
isDeleted: false,
skills: { '$in': [ ObjectId('613b9951e42a5203c421cbcc'), ObjectId('613b9951e42a5203c421cbcd') ] },
interests: { '$in': [ ObjectId('613b9951e42a5203c421cbce'), ObjectId('613b9951e42a5203c421cbcf') ] },
university: { '$in': [ ObjectId('613b9951e42a5203c421cbd0'), ObjectId('613b9951e42a5203c421cbd1') ] },
title: { '$in': [ ObjectId('613b785b7bacfe1336ab9dbf'), ObjectId('613b9951e42a5203c421cbd2') ] }
});
这工作得很好,但是当我在 mongoose find() 上推送相同的查询时,它返回空数组。请在下面找到猫鼬版本。
{
isDeleted: false,
skills: { '$in': [ '613b9951e42a5203c421cbcc', '613b9951e42a5203c421cbcd' ] },
interest: { '$in': [ '613b9951e42a5203c421cbce', '613b9951e42a5203c421cbcf' ] },
university: { '$in': [ '613b9951e42a5203c421cbd0', '613b9951e42a5203c421cbd1' ] },
title: { '$in': [ '613b785b7bacfe1336ab9dbf', '613b9951e42a5203c421cbd2' ] }
}
请注意,上面是我从前端本身得到的请求,我只是在推动它去寻找。
请找到这些特定字段的架构结构,
{
skills: [
{ type: schema.Types.ObjectId, ref: "Skills" }
],
interests: [
{ type: schema.Types.ObjectId, ref: "Interests" }
],
university: [{ type: schema.Types.ObjectId, ref: "University" }],
title: [{ type: schema.Types.ObjectId, ref: "Titles"}]
}
这是我正在使用的 find() 函数,
if (
this.req.body &&
this.req.body.filterParam &&
!_.isEmpty(this.req.body.filterParam)
) {
makeQuery = JSON.parse(JSON.stringify(this.req.body.filterParam));
}
if(_.isEmpty(this.req.body.searchText) && _.isEmpty(this.req.body.filterParam)) {
makeQuery = { isDeleted: false };
}
console.log(makeQuery);
let getListOfUsers = await Users.find(makeQuery)
.sort(sort)
.skip(skip)
.limit(perPage)
.populate("skills", { type: 1 }, { isDeleted: false })
.populate("interests", { type: 1 }, { isDeleted: false })
.populate("university", { type: 1 }, { isDeleted: false })
.populate("business_tags", { type: 1 }, { isDeleted: false })
.populate("title", { type: 1 }, { isDeleted: false })
.populate("likesUserManagement", { likedFlag: 1 }, { isDeleted: false, likedFlag: true, createdBy: currentUser })
.select({
password: 0,
status: 0,
emailVerificationStatus: 0,
isProfileCompleted: 0,
isDeleted: 0,
previouslyUsedPasswords: 0,
ifForgetOtpVerified: 0,
portfolio_name: 0,
portfolio_s3_name: 0,
image_name: 0,
createdAt: 0,
updatedAt: 0,
__v: 0,
});
谁能帮我解决这个问题。我被这个困住了。请帮我。谢谢。
解决方案
推荐阅读
- azure - 使用 Terraform 的 Azure 数据工厂诊断设置的资源特定目标表
- if-statement - 我可以将 IF 函数的值转换为方程式吗?
- go - 如何自动使测试在包内并行运行?
- python-3.x - 如何将具有相同标题的数据移动到同一列中?
- php - 网站的 PHP 文件显示错误:找不到驱动程序
- android - 如何在抽屉布局下方放置广告?
- java - 每当 App 在 android pie 中被杀死时,服务也会被杀死
- android - Google 登录帐户弹出窗口未显示错误 12501
- c# - 实体框架默认排除归档记录
- arm - 使用“Blue Pill”或 stm32f103c8 进行蓝牙编程