Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个模型,不需要每个属性。我想查询模型并返回定义属性的所有实例。
这是我认为代码应该看起来的样子,但它不起作用。任何想法或链接到一些详细的文档?
MyModel.find() .where({ "propertyThatMayExist" : { "!=" : undefined } });
提前致谢!
最简单的方法是针对null. 正确的运算符是!or not:
null
!
not
MyModel.find().where({propertyThatMayExist: {'!': null}}).exec(console.log);
这假设您有时不想null为实例显式设置属性,这对于某些数据库来说无论如何都是有问题的(想想 MySQL,如果没有填写大多数字段,它默认为 NULL)。