Database/Mongo
MongoDB - 기본 CRUD 예제 2
Jeffrey Oh
2023. 3. 6. 15:03
샘플 데이터는 MongoDB Atlas Load Sample Dataset
이용함
예제는 아래 것을 사용sample_guides
dbplanets
collection
기본적으로 함수로 조회할 때는 document 내에서 처리한다
findOne
1개의 document 를 조회
db.planets.findOne({ name : "Mars" })
find
여러개의 document 를 query filter 를 사용하여 조회
and
db.planets.find({
hasRings : true, // , 는 and
orderFromSun: { $lte: 6 }
})
또는
db.planets.find({
$and: [
{ hasRings : true },
{ orderFromSun: { $lte: 6 } }
]
})
or
db.planets.find({
$or: [
{ hasRings : { $ne: false } },
{ orderFromSun: { $gt: 6 } }
]
})
in
db.planets.find({
mainAtmosphere : { $in : ['O2'] }
})