mongoDB 접속
$ mongosh mongodb://localhost:27017/admin?authSource=admin --username jamie
데이터 추가 MongoDB에 여러 데이터를 넣어보자(Insert & Import)
testDB 접근
$ mongosh mongodb://localhost:27017/testDB?authSource=admin --username jamie
Enter password: ***********
> use testDB
switched to db testDB
> myCursor = db.inventory.find( { status: "A", qty: { $lt: 30 } } )
[
{
_id: ObjectId("5fc73f0993426845fee7ba69"),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
}
]
> myCursor = db.inventory.find( { $or: [ { status: "A" }, { qty: { $lt: 30 } } ] } )
[
{
_id: ObjectId("5fc73f0993426845fee7ba69"),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId("5fc73f0993426845fee7ba6a"),
item: 'postcard',
qty: 45,
size: { h: 10, w: 15.25, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId("5fc73f0993426845fee7ba6b"),
item: 'notebook',
qty: 50,
size: { h: 8.5, w: 11, uom: 'in' },
status: 'A'
}
]
> myCursor = db.inventory.find( {
... status: "A",
... $or: [ { qty: { $lt: 30 } }, { item: /^p/ } ]
... } )
[
{
_id: ObjectId("5fc73f0993426845fee7ba69"),
item: 'journal',
qty: 25,
size: { h: 14, w: 21, uom: 'cm' },
status: 'A'
},
{
_id: ObjectId("5fc73f0993426845fee7ba6a"),
item: 'postcard',
qty: 45,
size: { h: 10, w: 15.25, uom: 'cm' },
status: 'A'
}
]
/^p/
사용MongoDB 공식 가이드 - https://docs.mongodb.com/guides/server/read_operators/