MongoDB #8
نویسنده: برات جوادی
تاریخ: ۱۳۹۳/۱۱/۰۶ ۱۷:۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
>db.COLLECTION_NAME.find()
>db.mycol.find().pretty()
>db.mycol.find().pretty()
{
"_id": ObjectId(7df78ad8902c),
"title": "MongoDB Overview",
"description": "MongoDB is no sql database",
"by": "tutorials point",
"url": "http://www.tutorialspoint.com",
"tags": ["mongodb", "database", "NoSQL"],
"likes": "100"
}
> | عملگر | گرامر | مثال | مشابه در پایگاه داده رابطه ای |
| Equality | {<key>:<value>} | ()db.mycol.find({"by":"tutorialspoint"}).pretty | ' where by = 'tutorials point |
| Less Than | {<key>:{$lt:<value>}} | ()db.mycol.find({"likes":{$lt:50}}).pretty | where likes < 50 |
| Less Than Equals | {<key>:{$lte:<value>}} | ()db.mycol.find({"likes":{$lte:50}}).pretty | where likes <= 50 |
| Greater Than | {<key>:{$gt:<value>}} | ()db.mycol.find({"likes":{$gt:50}}).pretty | where likes > 50 |
| Greater Than Equals | {<key>:{$gte:<value>}} | ()db.mycol.find({"likes":{$gte:50}}).pretty | where likes >= 5 0 |
| Not Equals | {<key>:{$ne:<value>}} | ()db.mycol.find({"likes":{$ne:50}}).pretty | where likes != 50 |
>db.mycol.find({key1:value1, key2:value2}).pretty() >db.mycol.find({"by":"tutorials point","title": "MongoDB Overview"}).pretty()
{
"_id": ObjectId(7df78ad8902c),
"title": "MongoDB Overview",
"description": "MongoDB is no sql database",
"by": "tutorials point",
"url": "http://www.tutorialspoint.com",
"tags": ["mongodb", "database", "NoSQL"],
"likes": "100"
}
> >db.mycol.find(
{
$or: [
{key1: value1}, {key2:value2}
]
}
).pretty() >db.mycol.find({$or:[{"by":"tutorials point"},{"title": "MongoDB Overview"}]}).pretty()
{
"_id": ObjectId(7df78ad8902c),
"title": "MongoDB Overview",
"description": "MongoDB is no sql database",
"by": "tutorials point",
"url": "http://www.tutorialspoint.com",
"tags": ["mongodb", "database", "NoSQL"],
"likes": "100"
}
> >db.mycol.find("likes": {$gt:10}, $or: [{"by": "tutorials point"}, {"title": "MongoDB Overview"}] }).pretty()
{
"_id": ObjectId(7df78ad8902c),
"title": "MongoDB Overview",
"description": "MongoDB is no sql database",
"by": "tutorials point",
"url": "http://www.tutorialspoint.com",
"tags": ["mongodb", "database", "NoSQL"],
"likes": "100"
}
>