(1) Select from collection:
=======================
db.players.find({"position" : "Left Wing"})
db.players.find( {"position" : "Left Wing"} ).pretty()
(2) Using mulitiple conditions
==========================
db.players.find( {"position" : "Center","age" : 26} ).pretty()
(3) Using OR operator
=================
db.players.find(
{ $or:
[
{"position" : "Left Wing"},{"position" : "Right Wing"}
]
}
)
(4) Conditional Select Statements
Greater than, Less than, Grater than equal to, Less than equal to, Not equal
=======================================================
db.players.find(
{"age":{$gt:30}
}
)
db.players.find(
{"age":{$gte:28}
}
)
db.players.find(
{"age":{$lt:30}
}
)
db.players.find(
{"age":{$ne:29}
}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
}
)
(5) Limitting Columns in the Display
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
).limit(1)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
).skip(1)
(6)By Sort order
db.users.find().sort(name:1})
=======================
db.players.find({"position" : "Left Wing"})
db.players.find( {"position" : "Left Wing"} ).pretty()
(2) Using mulitiple conditions
==========================
db.players.find( {"position" : "Center","age" : 26} ).pretty()
(3) Using OR operator
=================
db.players.find(
{ $or:
[
{"position" : "Left Wing"},{"position" : "Right Wing"}
]
}
)
(4) Conditional Select Statements
Greater than, Less than, Grater than equal to, Less than equal to, Not equal
=======================================================
db.players.find(
{"age":{$gt:30}
}
)
db.players.find(
{"age":{$gte:28}
}
)
db.players.find(
{"age":{$lt:30}
}
)
db.players.find(
{"age":{$ne:29}
}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
}
)
(5) Limitting Columns in the Display
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
).limit(1)
db.players.find(
{$or:
[
{"position":"Center"}, {"age":{lte:29}}
]
},
{"name":1,"age":1,_id:0}
).skip(1)
(6)By Sort order
db.users.find().sort(name:1})
No comments:
Post a Comment