3 回答
TA贡献1921条经验 获得超9个赞
// Find all docs that have at least a second name array element.db.accommodations.find({'name.1': {$exists: true}})
db.accommodations.createIndex( {'name.1': 1}, {partialFilterExpression: {'name.1': {$exists: true}}});
TA贡献1828条经验 获得超13个赞
$where
{$nor: [ {name: {$exists: false}}, {name: {$size: 0}}, {name: {$size: 1}}]}
> db.test.save({})
> db.test.save({name: []})
> db.test.save({name: ['George']})
> db.test.save({name: ['George', 'Raymond']})
> db.test.save({name: ['George', 'Raymond', 'Richard']})
> db.test.save({name: ['George', 'Raymond', 'Richard', 'Martin']})
> db.test.find({$nor: [{name: {$exists: false}}, {name: {$size: 0}}, {name: {$size: 1}}]})
{ "_id" : ObjectId("511907e3fb13145a3d2e225b"), "name" : [ "George", "Raymond" ] }
{ "_id" : ObjectId("511907e3fb13145a3d2e225c"), "name" : [ "George", "Raymond", "Richard" ] }
{ "_id" : ObjectId("511907e3fb13145a3d2e225d"), "name" : [ "George", "Raymond", "Richard", "Martin" ] }
>
- 3 回答
- 0 关注
- 892 浏览
添加回答
举报