gpt4 book ai didi

javascript - mongodb过滤器不工作

转载 作者:行者123 更新时间:2023-11-30 12:09:53 25 4
gpt4 key购买 nike

我正在尝试对我的数据库运行如下查询:

filter.customerProfile = { $exists: true };
console.log("filter: " + JSON.stringify(filter));
this.accountsAPI.find(filter, cb);

在我打印的回调中:

console.log('first element: ', JSON.stringify(accounts[0]));

我的输出:

filter: {"customerProfile":{"$exists":true}}
first element: {"username":"aabrahams","firstName":"Arthur","lastName":"Abrahams","DOB":"1981-07-11","email":"aabrahams@gmail.com","adminProfile":[{"displayUsername":"Art Abrahams","active":true,"priceEdits":[],"products":[],"productEdits":[],"jobCancellationApprovals":[],"partnerApprovals":[]}],"_id":"TkJNoSogUaJFKIHU"}

基本上,它会返回所有用户,而不仅仅是那些具有“customerProfile”的用户,而且我使用的过滤器甚至都不重要。我尝试添加 "$ne":null 但没有帮助。

最佳答案

根据 feathers' documentation你用query做一个过滤条件:

var filter = {
query: {
customerProfile: {
$exists: true
}
}
}
this.accountsAPI.find(filter, cb);

关于javascript - mongodb过滤器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34123120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com