MST
星途 面试题库

面试题:MongoDB内嵌文档中等难度查询问题

假设有一个MongoDB集合,其中文档结构如下:{ '_id': ObjectId('64c3c0c9d5c09506559d955f'), 'name': 'Alice', 'orders': [ { 'order_id': 1, 'product': 'Book', 'quantity': 3, 'price': 10 }, { 'order_id': 2, 'product': 'Pen', 'quantity': 5, 'price': 2 } ] } 。现在要查询出所有购买了数量大于4个商品的用户,写出对应的查询语句。
11.5万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试
db.collection.find({
    "orders.quantity": { $gt: 4 }
})