Mongo DB随笔

Mongo DB——随笔

查询:

select * from 0922test;
db.getCollection('0922test').find();

select * from 0922test where name='0922test';
db.getCollection('0922test').find({'name':'0922test'});

select * from 0922test where age>30;
db.getCollection('0922test').find({'age':{$gt:"30"}}).pretty();

select * from 0922test where  name='aaa'  and age>30;
db.getCollection('0922test').find({'name':'aaa','age':{$gt:"30"}}).pretty();
>    $gt
>=  $gte
<    $lt
<=  $lte
!=   $ne
select * from 0922test  where   age>30 and name = 'aaa' or name = 'bbb';
db.getCollection('0922test').find({{'age':{$gt:"30"}},$or:[{'name':'aaa'},{'name':bbb'}]}).pretty();
select name from 0922test;
db.getCollection('0922test').find({},{'name':1});

删除集合:

db.getCollection('0922test').drop();

删除文档:
query :(可选)删除的文档的条件。
justOne : (可选)如果设为 true 或 1,则只删除一个文档,如果不设置该参数,或使用默认值 false,则删除所有匹配条件的文档。
writeConcern :(可选)抛出异常的级别。

delete from 0922test where name is null;
db.getCollection("0922test").remove({'name':{$exists: true}});

插入数据:

db.getCollection("0922test").insert( {
    title: "0923",
    description: "MongoDB",
    by: "菜出差程点多",
    url: "http://www.runoob.com",
    tags: [
        "mongodb",
        "database",
        "NoSQL"
        ],
    likes: 100
} );


db.getCollection("0922test").insert( {
    name: "gggh",
    title: "0923"
} );

更新:
query : update的查询条件,类似sql update查询内where后面的。
update : update的对象和一些更新的操作符(如 , , ,inc…)等,也可以理解为sql update查询内set后面的
upsert : 可选,这个参数的意思是,如果不存在update的记录,是否插入objNew,true为插入,默认是false,不插入。
multi : 可选,mongodb 默认是false,只更新找到的第一条记录,如果这个参数为true,就把按条件查出来多条记录全部更新。
writeConcern :可选,抛出异常的级别。

update 0922test set title ='0923';
db.getCollection("0922test").update({},{$set :{'title':'0923'}}, {multi:true});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值