MST

星途 面试题库

面试题:MongoDB与SQL在条件查询语法上的差异

假设我们有一个存储用户信息的数据库,在SQL中有一个users表,在MongoDB中有一个users集合,表/集合中都有字段name、age和email。请分别写出SQL和MongoDB查询年龄大于30岁且邮箱包含'example.com'的用户信息的语法。
19.0万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试

SQL

SELECT name, age, email
FROM users
WHERE age > 30 AND email LIKE '%example.com%';

MongoDB

db.users.find({
    age: { $gt: 30 },
    email: { $regex: 'example.com' }
});