2023年7月21日发(作者:)
MongoDB常⽤语法⼀、MongoDB简介
MongoDB是⼀个基于分布式⽂件存储 的数据库,是当前 NoSQL 数据库产品中最热门的⼀种。 它的数据是以⽂档的形式存储数据的,风格⽐较类似于JSON,键和值的⽅式。们把这个数据格式称作 "[BSON]"即 "Binary SerializeddOcument Notation.",键是字符串,值可以是其他的⽂档,数组,和数组⽂档。⼆、mongodb基本查询语句介绍1、select 查询select * from product ;等同于
();2、select指定的列select id,name,code from product ;等同于
({},{'id':1,'name':1,'code':1}); ---1代表这些列都显⽰。注:第⼀个{}中放where条件3、where条件andselect name,code from product where class=1 and code='564';等同于({'class':1 , 'code':'564'},{'name':1,'code':1});----冒号表⽰键和值,多个键值⽤逗号隔开4、where条件⽐较值 >($gt) <($lt) >=($gte) <= ($lte)select name,code from product where AddTime>='2019-10-01' and AddTime<'2019-11-01';等同于({AddTime: {'$gte':new Date(2019,09,01),'$lt':new Date(2019,10,01) } },{'name':1,'code':1});----new Date(2019,09,01) 表⽰2019-10-01,后⾯会讲5、where条件 in($in) 、not in($nin) 、 or ($or)select name,code from product where id in (1,3,4)等同于({ 'id':{ '$in': [1,3,4] } },{'name':1,'code':1});
select name,code from product where id=1 or code ='354'等同于( { '$or' : [ {'id':1} , {'code':'354'} ] },{'name':1, 'code':1} );
6、where条件之 like模糊匹配select name,code from product where Remark like '%商品状态%'等同于( { Remark: /商品状态/ },{'name':1, 'code':1} );
select name,code from product where Remark like '商品状态%'等同于( { Remark: /^商品状态/ },{'name':1, 'code':1} );
三、基本聚合函数count、distinct、group1、count 计数函数语法:(
发布者:admin,转转请注明出处:http://www.yc00.com/web/1689896321a293116.html
评论列表(0条)