2016-01-13 34 views
0

我想在我的数据库中找到其中有空值的字段。我在这里阅读了一些其他的线程,你可以尝试使用$ ne(不等于),但没有为我工作,所以我认为这可能是其他事情我做错了。查找具有空值的字段并在MongoDB中对它们进行计数

这是从我的数据库为例:

{ "_id" : ObjectId("5695553244aec8a25d162698"), "DBLPKey" : "journals/software/Goth08a", "LastModified" : "2011-11-07", "Authors" : [ { "Name" : "Greg Goth", "Affiliation" : null } ], "Title" : "Ultralarge Systems: Redefining Software Engineering?", "Pages" : "91-94", "Year" : "2008", "Volume" : "25", "Journal" : "IEEE Software", "Number" : "3", "ElectronicEdition" : "http://doi.ieeecomputersociety.org/10.1109/MS.2008.82", "LocalURL" : "db/journals/software/software25.html#Goth08a", "Abstracts" : "Ultra-Large-Scale Systems: The Software Challenge of the Future, a report produced by Carnegie Mellon University's Software Engineering Institute, just might be a watershed blueprint for the next generation of top-level software design. Although it's written with a distinct slant toward the US military's future requirements, its description of how the fundamental principles of software design will change in a global economy—defined by ubiquitous computing—are finding wide appeal." } 

我想在这里找到该字段名为所属里面作者领域。 我曾尝试此查询:

db.Articles.find({Affiliation:{ $ne: null}}) 

但是,这并不为我工作。是否因为我不知何故必须告诉MongodDB它在字段Author中?还是我误解了或错过了一些其他的东西?

回答

2

您可以使用elemMatch

试试这个,

db.Articles.find({ "Authors": { $elemMatch: {"Affiliation" : null } } }) 
+0

会立即尝试! :) 编辑:谢谢你,完美的工作! :) – anderssinho

相关问题