MongoDB的运行查询就像如SQL! [英] mongoDB run queries just like as SQL !

查看:543
本文介绍了MongoDB的运行查询就像如SQL!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public IQueryable<T> GetRecords<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression, int from, int first) where T : class, new()
    {
        first = first == 0 ? 30 : first;
        return _db.GetCollection<T>(collectionName).Linq().Where(expression).Skip(from).Take(first);
    }
    var x = GetRecords<Event>(p => true, 0, 12222);
    string eventJson = new JavaScriptSerializer().Serialize(x);

这个功能从MongoDB中获取数据。

this function get the data from mongoDB.

    SqlDataReader dr = SqlHelper.ExecuteReader("Select Top(12222)* From NewsFeed");
    string eventJson = new JavaScriptSerializer().Serialize(dr);

和这从SQL Server。搜索结果
我试图来衡量执行时间为他们每个人,结果是:
结果蒙戈:172ms结果
SQL:185ms。结果
,但我了解MongoDB的应该比SQL快太多了吧!?!

and this from SQL Server .

I've tried to measure the execute time for each of them and the result was :
Mongo : 172ms
SQL : 185ms .
but as I know the mongoDB should be too much faster than SQL , right !?!

推荐答案

MongoDB是在这样一个简单的查询不一定是谈出来的,执行SQL服务器;速度优势是,当你有辅助数据的采集。我不知道你的域名是什么样子,而是一个常见的例子是一个博客。在SQL数据库中,你将有一个职位表,意见表,authors表,等您的查询检索所有为单个博客文章显示要求要么包括一些加入或多个查询数据(无论哪种方式会影响业绩略)。在NoSQL的数据库中,可能有一个表,文章。没有人查询连接将拉回所有必需的数据。

MongoDB isn't necessarily about out-performing SQL server in a simple query like that; The speed advantage comes in when you have ancillary data. I don't know what your domain looks like, but a common example is a blog. In a SQL database, you would have a posts table, a comments table, an authors table, etc. Your query to retrieve all the data required for a single blog post display would either include a few joins or multiple queries (either way will affect the performance a bit). In a NoSQL database, there could be a single table, Posts. One query with no joins will pull back all required data.

这是一个不错的博客文章谈论的NoSQL类型的商店和关系存储之间的不同方法。

这篇关于MongoDB的运行查询就像如SQL!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆