$et

语法

  1. { <字段名>: { $et: <值> } }

描述

指定相等条件,$et 匹配符匹配记录中某个字段的值等于指定的值。

示例

在集合 sample.employee 插入4条记录:

  1. > db.sample.employee.insert( { "id": 1, "item": { "name": "Tom", "code": "123" } } )
  2. > db.sample.employee.insert( { "id": 2, "item": { "name": "Jack", "code": "123" } } )
  3. > db.sample.employee.insert( { "id": 3, "item": { "name": "Mike", "code": "456" } } )
  4. > db.sample.employee.insert( { "id": 4, "item": { "name": "Lucy", "code": "789" }, "phone": [ "135", "177" ] } )

SequoiaDB shell运行如下:

  • 查询“id”字段值等于1的记录:

    1. > db.sample.employee.find( { "id": { "$et": 1 } } )
    2. {
    3. "_id": {
    4. "$oid": "5822b0472b4c38286d000009"
    5. },
    6. "id": 1,
    7. "item": {
    8. "name": "Tom",
    9. "code": "123"
    10. }
    11. }

    查询相当于:

    1. > db.sample.employee.find( { "id": 1 } )
  • 匹配嵌套字段“name”的值等于“Jack”的记录:

    1. > db.sample.employee.find( { "item.name": { "$et": "Jack" } } )
    2. {
    3. "_id": {
    4. "$oid": "5822b04b2b4c38286d00000a"
    5. },
    6. "id": 2,
    7. "item": {
    8. "name": "Jack",
    9. "code": "123"
    10. }
    11. }
    12. Return 1 row(s).

    查询相当于:

    1. > db.sample.employee.find( { "item.name": "Jack" } )
  • 匹配数组元素:

    1. > db.sample.employee.find( { "phone": { "$et": "135" } } )
    2. {
    3. "_id": {
    4. "$oid": "5822b0562b4c38286d00000c"
    5. },
    6. "id": 4,
    7. "item": {
    8. "name": "Lucy",
    9. "code": "789"
    10. },
    11. "phone": [
    12. "135",
    13. "177"
    14. ]
    15. }
    16. Return 1 row(s).

    查询相当于:

    1. > db.sample.employee.find( { "phone": "135" } )