添加数组元素(去重)

db.collection.updateMany({}, {$addToSet: {arrayName: element}})

添加数组元素(不去重)

db.collection.update({}, {$push: {arrayName: element}})

删除数组某元素

db.collection.update({},{$pull: {arrayName: element}})

查找数组为空的数据

db.collection.find({arrayName: {$size: 0}})

查找数组不为空的数据

db.collection.find({"arrayName.1": {$exists: true}})
Scroll to Top