1

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

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 并没有帮助。

4

1 回答 1

3

根据羽毛的文档,您使用query制作过滤条件:

var filter = {
  query: {
    customerProfile: { 
      $exists: true 
    }
  }
}
this.accountsAPI.find(filter, cb);
于 2015-12-06T22:22:56.757 回答