6.1.1コマンド例
MongoDB検索ウィンドウで使用するコマンドの例です。
-- create collection
db.createCollection('sample7');
-- insert
db.sample.insert({name: "Audi", price: 52642});
db.getCollection("sample").insert({name: "Audi", price: 52642});
db.getCollection("sample").insertMany(
[
{ name: 'John', address: 'Highway 71'},
{ name: 'Peter', address: 'Lowstreet 4'},
{ name: 'Amy', address: 'Apple st 652'},
{ name: 'Hannah', address: 'Mountain 21'},
{ name: 'Michael', address: 'Valley 345'},
{ name: 'Sandy', address: 'Ocean blvd 2'},
{ name: 'Betty', address: 'Green Grass 1'},
{ name: 'Richard', address: 'Sky st 331'},
{ name: 'Susan', address: 'One way 98'},
{ name: 'Vicky', address: 'Yellow Garden 2'},
{ name: 'Ben', address: 'Park Lane 38'},
{ name: 'William', address: 'Central st 954'},
{ name: 'Chuck', address: 'Main Road 989'},
{ name: 'Viola', address: 'Sideway 1633'}
]
);
-- limit
db.getCollection("sample").find().limit(5);
-- update
db.getCollection("sample").update({price:52642}, {$set:{name:"audio-52"}});
db.getCollection("sample").update({name:/^1A/}, {$set:{name:"up-audio-52"}});
db.getCollection("sample").updateMany({name:/^up/}, {$set:{name:"up-audio-52"}});
-- find
db.sample.find();
db.getCollection("sample").find({name: "Audi"});
-- sort
db.getCollection("sample").find({name: "Audi"}).sort({name: 1});
db.getCollection("sample").find().sort({price: 1});
db.getCollection("sample").find().sort({price: -1});
-- delete
db.getCollection("sample").delete({name: "Audi"});
-- drop
db.getCollection("sample2").drop();
<span id="pageNum"/>