希望进行以下查询:
Entrant
.find
enterDate : oneMonthAgo
confirmed : true
.where('pincode.length > 0')
.exec (err,entrants)->
我是否正确使用了where子句?我想选择那些pincode
不为空的文档。
如果您正在使用查询 API,应该可以像这样完成:
Entrant.where("pincode").ne(null)
这将产生一个类似于mongo查询的查询:
entrants.find({ pincode: { $ne: null } })
以下是几个有用的链接:
我最终来到这里,我的问题是我正在查询
{$not: {email: /@domain.com/}}
取代
{email: {$not: /@domain.com/}}
大家好,我找到了一个可能的解决方案。我意识到Mongo中不存在连接(join),这就是为什么您需要首先查询具有所需角色的用户ID,然后再对配置文件文档进行另一个查询,类似于以下内容:
const exclude: string = '-_id -created_at -gallery -wallet -MaxRequestersPerBooking -active -__v';
// Get the _ids of users with the role equal to role.
await User.find({role: role}, {_id: 1, role: 1, name: 1}, function(err, docs) {
// Map the docs into an array of just the _ids
var ids = docs.map(function(doc) { return doc._id; });
// Get the profiles whose users are in that set.
Profile.find({user: {$in: ids}}, function(err, profiles) {
// docs contains your answer
res.json({
code: 200,
profiles: profiles,
page: page
})
})
.select(exclude)
.populate({
path: 'user',
select: '-password -verified -_id -__v'
// group: { role: "$role"}
})
});
统计文档总数,其中字段值不等于指定值。
async function getRegisterUser() {
return Login.count({"role": { $ne: 'Super Admin' }}, (err, totResUser) => {
if (err) {
return err;
}
return totResUser;
})
}
const profiles = await Profile.find({ user: {$exists: true, $ne: null }})
.select("-gallery")
.sort( {_id: -1} )
.skip( skip )
.limit(10)
.select(exclude)
.populate({
path: 'user',
match: { role: {$eq: customer}},
select: '-password -verified -_id -__v'
})
.exec();
And I get this result, how can I remove from the results the user:null colletions? . I meant, I dont want to get the profile when user is null (the role does not match).
{
"code": 200,
"profiles": [
{
"description": null,
"province": "West Midlands",
"country": "UK",
"postal_code": "83000",
"user": null
},
{
"description": null,
"province": "Madrid",
"country": "Spain",
"postal_code": "43000",
"user": {
"role": "customer",
"name": "pedrita",
"email": "myemail@gmail.com",
"created_at": "2020-06-05T11:05:36.450Z"
}
}
],
"page": 1
}
提前致谢。
...("myArraySubDoc[0].someValue").ne(true)
? - Stephan Kristynwhere("myArraySubDoc.0.someValue").ne(true)
- numbers1311407