猫鼬查询,其中值不为null [英] Mongoose query where value is not null

查看:85
本文介绍了猫鼬查询,其中值不为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望执行以下查询:

Entrant
    .find
      enterDate : oneMonthAgo
      confirmed : true
    .where('pincode.length > 0')
    .exec (err,entrants)->

我在正确地执行where子句吗?我想选择pincode不为空的文档.

Am I doing the where clause properly? I want to select documents where pincode is not null.

推荐答案

您应该能够做到这一点(因为您正在使用查询api):

You should be able to do this like (as you're using the query api):

Entrant.where("pincode").ne(null)

...将导致类似于以下内容的mongo查询:

... which will result in a mongo query resembling:

entrants.find({ pincode: { $ne: null } })

一些可能有用的链接:

  • The mongoose query api
  • The docs for mongo query operators

这篇关于猫鼬查询,其中值不为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆