且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB嵌套OR/AND在哪里?

更新时间:2022-03-17 09:46:45

MongoDB中的查询如下:

The query in MongoDB looks like:

Database.collection_name.find(
    // This is the condition
    {
        $and: [
           {
               $or: [
                   {province: 'nb'},
                   {province: 'on'}
               ]
           },
           {
               city: "toronto"
           },
           {
               first_name: "steven"
           }
        ]
    },

    // Specify the fields that you need
    {
        first_name: 1,
        _id: 1
    }
)

$ and 的文档 MongoDB的一些示例和官方文档可在此处.

Some examples and the official documentation for MongoDB find here.