OR trong MongoDB

Cú pháp

Để truy vấn Document dựa trên điều kiện OR, bạn cần sử dụng từ khóa $or. Cú pháp cơ bản của OR trong MongoDB như sau:

>db.mycol.find({
$or: [{key1: value1}, {key2:value2}]
}).pretty()

Ví dụ

Ví dụ sau sẽ hiển thị tất cả loạt bài hướng dẫn (tutorials) được viết bởi 'tutorials point' hoặc có title là 'MongoDB Overview'

>db.mycol.find({$or:[{"by":"tutorials point"},{"title": "MongoDB Overview"}]}).pretty()

{

"_id": ObjectId(7df78ad8902c),

"title": "MongoDB Overview",

"description": "MongoDB is no sql database",

"by": "tutorials point",

"url": "http://www.tutorialspoint.com",

"tags": ["mongodb", "database", "NoSQL"],

"likes": "100"

}

>

Last updated