首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

mongodb的装配与使用

2012-09-21 
mongodb的安装与使用?MongoDBMysql查询全部movies.find(new Document())SELECT * FROM movies条件查询movi

mongodb的安装与使用

?MongoDBMysql查询全部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 like ‘%Esr’

这里只举出了几个比较典型的例子,可以这么说,只要mysql可以完成的sql语句,在mongodb里面都可以实现.

热点排行