Skip to content

Instantly share code, notes, and snippets.

@tutumagi
Created September 15, 2021 10:00
Show Gist options
  • Save tutumagi/bdd3f57ccafaba2ca7ccd1c871913f81 to your computer and use it in GitHub Desktop.
Save tutumagi/bdd3f57ccafaba2ca7ccd1c871913f81 to your computer and use it in GitHub Desktop.
mongo shell #mongo
// 某个集合中的数组类型的字段至少有一个项目
db.getCollection('tbl_land').find({
"$someArray.0": {
"$exists": true,
}
})
// 查询某个字段至少有一个 key 的所有结果
db.getCollection('tbl_land').find({
"$expr": {
"$gt": [ { "$size": { "$objectToArray": "$ownEntities" } }, 0]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment