1. 程式人生 > >Mongodb 相關操作

Mongodb 相關操作

filter height shell let 查詢 fir cut ace mys

Shell 命令 和 Mysql 對比

查詢數據

等於:db.col.find({"delete_flag": "N"}).pretty()

小於:db.col.find({"count": {$lt: 10}}).pretty()

小於(lt: less than)

小於等於 (lte: less than or equal)

大於(gt: greater than)

大於等於 (gte: greater than or equal)

where delete_flag = 'N'

where count < 10

更新數據

db.col.update({'phone_number': { $gt : '18800000000' }}, {$set:{'full_name': 'Dake'}},

update test set full_name = 'Dake' where phone_number = '18800000000'

插入數據

db.col.insert({

phone_number: '18800000000',

full_name: 'Dake',

delete_flag: 'N'

})

insert into test (phone_number, full_name, delete_flag)

values ('18810160000', 'Dake', 'N')

刪除數據

db.col.remove({'phone_number': '18800000000'})

delete from test where phone_number = '18800000000'

在 php 7.0 上的應用

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = ['full_name' => ['$eq' => 'Dake']]; // where full_name = 'Dake'
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('test.col', $query);
echo '<pre>';
foreach ($cursor as $document)
{
    print_r($document);
}

Mongodb 相關操作