【发布时间】:2013-08-28 16:13:49
【问题描述】:
好吧,我运行一个字段匹配:
db.bios.find( { "Country":"Netherlands" } )
我怎样才能带上所有文件,但不带"Country":"Netherlands" 的文件?
是否也可以携带所有文件但没有两个国家/地区?
【问题讨论】:
标签: mongodb pymongo mongodb-query
好吧,我运行一个字段匹配:
db.bios.find( { "Country":"Netherlands" } )
我怎样才能带上所有文件,但不带"Country":"Netherlands" 的文件?
是否也可以携带所有文件但没有两个国家/地区?
【问题讨论】:
标签: mongodb pymongo mongodb-query
例如:
db.bios.find( { Country: { $nin: ["Country1", "Country2"] } } )
$ne 仅代表一个国家/地区:
db.bios.find( { Country: { $ne: "Country1" } } )
【讨论】:
您可以将$ne-operator(不等于)用于单个值。
db.bios.find( { "Country": { $ne: "Netherlands" } } );
要排除多个值,您可以使用$nin(not-in)运算符,它允许您传递一组值:
db.bios.find( { "Country": { $nin: [ "Netherlands", "Belgium", "Luxembourg" ] } );
【讨论】: