Mongodb 基础

A.Mongodb与mysql语句对比

  MongoDB Mysql
查询全部 movies.find(new Document()) SELECT * FROM movies
条件查询 movies.Find(new Document { { "title", "Hello Esr" } }); SELECT * FROM movies WHERE title= 'foobar'
查询数量 movies.Find(new Document { { "title", "测试2" } }).Documents.Count(); SELECT COUNT(*) FROM movies WHERE `title` = 'foobar'
数量范围查询 1, movies.Find(new Document().Add("$where", new Code("this.num > 50")));

2, movies.Find(new Document().Add("num",  new Document().Add("$gt",50)));
($gt : > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=)

3,movies.Find("this.num > 50");

4,movies.Find(new Document().Add("$where",new Code("function(x){ return this.num > 50};")));
select * from movies where num > 50
分页查询 movies.Find(new Document()).Skip(10).Limit(20); SELECT * FROM movies  limit 10,20
查询排序语句 movies.Find(new Document()).Sort(new Document() { { "num", -1 } }); SELECT * FROM movies ORDER BY num DESC
查询指定字段 movies.Find(new Document().Add("num", new Document().Add("$gt", 50)), 10, 0, new Document() { { "title", 1 } }); select title from movies where num > 50
插入语句 movies.Insert(new Document() { { "title", "测试" }, { "resuleData", DateTime.Now } }); INSERT INOT movies (`title`, `reauleDate`) values ('foobar',25)
删除语句 movies.Remove(new Document() { { "title", "Hello Esr" } }); DELETE * FROM movies
更新语句

movies.Update(new Document() { { "title", "测试2" } }
             , new Document() { { "title", "测试11111" } });

UPDATE movies SET `title` = ‘测试1111’ WHERE `title` = '测试1111'
Linq查询

(from item in db.GetCollection("movies").Linq()
                       where ((string)item["title"]).StartsWith("Esr")
                       select item);

select * from movies where title li

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值