-
Mongodb) db.collection.find() 요약 정리Programing Language/Mongodb 2022. 9. 5. 13:30728x90반응형
db.collection.find(query, projection)
초기화
db.test.insertMany([ { "name" : "Kim", "age" : 22, "major" : "CS"}, { "name" : "Lee", "age" : 24, "major" : "Japanense"}, { "name" : "Choi", "age" : 44, "major" : "Korean"} ])
1. All
[mongo Shell] db.test.find({}) [MySQL] SELECT * FROM test;
2. Equal
[mongo Shell] db.test.find( {name: "Kim"}, {_id: 0, name: 1, age: 1, major: 1} ) [MySQL] SELECT name, age, major FROM test WHERE name = "Kim";
3. In
[mongo Shell] db.test.find( {major: {$in: ["Korean", "japanese"]}} ) [MySQL] SELECT * FROM test WHERE major in ('Korean', 'japanese');
4. AND, OR, wildcard
[mongo Shell] db.test.find( { name: "A", $or: [{age: {$lt: 35}}, {major: /^J/}] } ) [MySQL] SELECT * FROM test WHERE name = 'A' and (age < 35 OR major LIKE 'J%');
참고) 비교문법
$eq = Matches values that are equal to a specified value. $gt > Matches values that are greater than a specified value. $gte >= Matches values that are greater than or equal to a specified value. $in Matches any of the values specified in an array. $lt < Matches values that are less than a specified value. $lte <= Matches values that are less than or equal to a specified value. $ne != Matches all values that are not equal to a specified value. $nin Matches none of the values specified in an array.
광고 클릭은 개발자 커피 공급에 도움이 됩니다!!
728x90반응형'Programing Language > Mongodb' 카테고리의 다른 글
MongoDB) mongodb Cloud에서 Databses Dump 하기 (0) 2022.06.20