Get the App
SLTechnology News&Howtos  ›  Database  › 

Query expression exercise

Shulou Source: shulou.com Published: 2022-06-01 14:03:27 11月20日 Update

Three query knowledge

Note: the following query is based on the list of goods on the ecshop website (ecs_goods).

In practice, you can take only part of the columns for easy viewing.

1: exercise for basic query where:

Identify goods that meet the following conditions

1.1: goods with a primary key of 32

Db.goods.find ({goods_id:32})

1. 2: all goods not in column 3 ($ne)

Db.goods.find ({cat_id: {$ne:3}}, {goods_id:1,cat_id:1,goods_name:1})

1.3goods priced above 3000 yuan in our store {$gt}

Db.goods.find ({shop_price: {$gt:3000}}, {goods_name:1,shop_price:1})

Goods whose price is less than or equal to 100RMB in our store ($lte)

Db.goods.find ({shop_price: {$lte:100}}, {goods_name:1,shop_price:1})

1.5: take out the goods in column 4 or 11 ($in)

Db.goods.find ({cat_id: {$in: [4Jing 11]}}, {goods_name:1,shop_price:1})

1.6: take out 100

Tags: Goods columns queries prices attributes documents foundations data conditions knowledge types websites expressions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Xiaomi Microsoft MariaDB