Chứa MongoDB
Ngày đăng:
25/12/2022
Trả lời:
0
Lượt xem:
109
Viết một truy vấn MongoDB để tìm Id, tên, quận và món ăn của nhà hàng cho những nhà hàng có chứa 'ces' là ba chữ cái cuối cùng của tên của nó Show Cơ cấu bộ sưu tập 'nhà hàng' { "address": { "building": "1007", "coord": [ -73.856077, 40.848447 ], "street": "Morris Park Ave", "zipcode": "10462" }, "borough": "Bronx", "cuisine": "Bakery", "grades": [ { "date": { "$date": 1393804800000 }, "grade": "A", "score": 2 }, { "date": { "$date": 1378857600000 }, "grade": "A", "score": 6 }, { "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 }, { "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 }, { "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 } ], "name": "Morris Park Bake Shop", "restaurant_id": "30075445" } Truy vấn
đầu ra { "_id" : ObjectId("564c2d949eb21ad392f17a5b"), "borough" : "Manhattan", "cuisine" : "American ", "name" : "Pieces", "restaurant_id" : "40399910" } { "_id" : ObjectId("564c2d949eb21ad392f17b1b"), "borough" : "Queens", "cuisine" : "American ", "name" : "S.M.R Restaurant Services", "restaurant_id" : "40403857" } { "_id" : ObjectId("564c2d949eb21ad392f17b21"), "borough" : "Manhattan", "cuisine" : "American ", "name" : "Good Shepherd Services", "restaurant_id" : "40403989" } { "_id" : ObjectId("564c2d949eb21ad392f17fd3"), "borough" : "Queens", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "The Ice Box-Ralph'S Famous Italian Ices", "restaurant_id" : "40690899" } { "_id" : ObjectId("564c2d949eb21ad392f181d6"), "borough" : "Brooklyn", "cuisine" : "Jewish/Kosher", "name" : "Alices", "restaurant_id" : "40782042" } { "_id" : ObjectId("564c2d949eb21ad392f183f0"), "borough" : "Manhattan", "cuisine" : "American ", "name" : "Re: Sources", "restaurant_id" : "40876068" } { "_id" : ObjectId("564c2d949eb21ad392f1867c"), "borough" : "Staten Island", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Cange'S Italian Ices", "restaurant_id" : "40966018" } { "_id" : ObjectId("564c2d949eb21ad392f18735"), "borough" : "Brooklyn", "cuisine" : "American ", "name" : "B.A.M. Cafe/Great Performances", "restaurant_id" : "40992170" } { "_id" : ObjectId("564c2d949eb21ad392f188c7"), "borough" : "Brooklyn", "cuisine" : "American ", "name" : "Barbara Blum Residence / Good Shepherd Services", "restaurant_id" : "41029591" } { "_id" : ObjectId("564c2d949eb21ad392f18eae"), "borough" : "Brooklyn", "cuisine" : "Soul Food", "name" : "Berts Restaurant & Catering Services", "restaurant_id" : "41184590" } { "_id" : ObjectId("564c2d949eb21ad392f1922c"), "borough" : "Staten Island", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Famous Italian Ices", "restaurant_id" : "41254301" } { "_id" : ObjectId("564c2d949eb21ad392f195fa"), "borough" : "Queens", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Famous Italian Ices", "restaurant_id" : "41316785" } { "_id" : ObjectId("564c2d949eb21ad392f197a6"), "borough" : "Staten Island", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Famous Italian Ices", "restaurant_id" : "41347936" } { "_id" : ObjectId("564c2d949eb21ad392f19908"), "borough" : "Manhattan", "cuisine" : "American ", "name" : "International Flavors & Fragrances", "restaurant_id" : "41370481" } { "_id" : ObjectId("564c2d949eb21ad392f19c8a"), "borough" : "Staten Island", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Ices", "restaurant_id" : "41410016" } { "_id" : ObjectId("564c2d949eb21ad392f19db3"), "borough" : "Manhattan", "cuisine" : "American ", "name" : "New York Stock Exchange Executive Services", "restaurant_id" : "41426518" } { "_id" : ObjectId("564c2d949eb21ad392f19e82"), "borough" : "Queens", "cuisine" : "Pizza", "name" : "Slices And Ices", "restaurant_id" : "41437112" } { "_id" : ObjectId("564c2d949eb21ad392f1a046"), "borough" : "Staten Island", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Famous Italian Ices", "restaurant_id" : "41459709" } { "_id" : ObjectId("564c2d949eb21ad392f1a9bb"), "borough" : "Manhattan", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices", "name" : "Ralph'S Famous Italian Ices", "restaurant_id" : "41573883" } { "_id" : ObjectId("564c2d949eb21ad392f1aacf"), "borough" : "Bronx", "cuisine" : "Caribbean", "name" : "7 Spices", "restaurant_id" : "41584120" } Type "it" for more Ghi chú. Đầu ra này được tạo bằng máy chủ MongoDB phiên bản 3. 6 Cải thiện giải pháp mẫu này và đăng mã của bạn qua Disqus Trước. Viết một truy vấn MongoDB để tìm Id, tên, quận và món ăn của nhà hàng cho những nhà hàng có chứa 'Wil' là ba chữ cái đầu tiên cho tên của nó. Mức độ khó của bài tập này là gì?
Làm cách nào để kiểm tra xem có thứ gì đó tồn tại trong MongoDB không?Trong MongoDB, chúng ta có thể kiểm tra sự tồn tại của trường trong tập hợp được chỉ định bằng cách sử dụng toán tử $exists . Khi giá trị của toán tử $exists được đặt thành true, thì toán tử này khớp với tài liệu chứa trường đã chỉ định (bao gồm cả tài liệu có giá trị của trường đó là null).
Làm cách nào để tìm chuỗi con trong chuỗi trong MongoDB?Bạn có thể sử dụng hàm $substr trong MongoDB để trích xuất một chuỗi con từ một chuỗi. Ví dụ cụ thể này trích xuất bốn ký tự từ trường có tiêu đề “fullString” bắt đầu từ vị trí 0.
Chuỗi trong MongoDB là gì?chuỗi. Một chuỗi thuật ngữ mà MongoDB phân tích cú pháp và sử dụng để truy vấn chỉ mục văn bản . MongoDB thực hiện tìm kiếm logic OR của các điều khoản trừ khi được chỉ định là một cụm từ. Xem Hành vi để biết thêm thông tin về lĩnh vực này.
Làm cách nào để tìm các đối tượng lồng nhau trong MongoDB?Truy cập tài liệu nhúng/lồng nhau –
. using dot notation and when you are using dot notation, then the field and the nested field must be inside the quotation marks. |