Mongodb allows you to query a specific column in a relational database.

Source: Internet
Author: User

Mongodb allows you to query a specific column in a relational database.

Recently in tornado \ mongodb \ ansible


The find () method in mongodb is awesome. You can upload all the tables in the set.


class Module_actionHandler(tornado.web.RequestHandler):    def get(self, *args, **kwargs):        coll = self.application.db.waitfish        hosts = coll.find({}, {'hostname':1,"_id":0})        modulenames = ['ping', 'setup', 'copy']        self.render(            "module_action.html",            hosts = hosts,            modulenames = modulenames,        )

Then in the template:

<select name="hostname">                {% for host in hosts %}                <option name="{{ host['hostname'] }}" >{{ host['hostname'] }}</option>                {% end %}</select>

Later I thought about the find () method to find all the tables, which is too much damage ..

So I went to see du Niang again, basically listing a lot of query commands and a lot of methods.

Finally, I chose this one:

Class Module_actionHandler (tornado. web. requestHandler): def get (self, * args, ** kwargs): coll = self. application. db. waitfish hosts = coll. find ({},{ 'hostname': 1, "_ id": 0}) # To explain, Here hostname: 1 indicates that the hostname column is returned, because the _ id column is returned every time, 0 is disabled. The template is also modulenames = ['ping', 'setup', 'copy'] self. render ("module_action.html", hosts = hosts, modulenames = modulenames ,)



Import data from apsaradb for Oracle to apsaradb for mongodb

First, make sure that you want to import data from a relational database to a NoSql database? This is what needs to be achieved.

I am also engaged in development. I recommend the following: do not try to convert a relational database to a non-relational database:
1. Saving maintenance costs;
2. Hardware and Software costs. Mongodb requires more storage space to store data. (Of course, the hardware configuration varies with different systems );
3. Distributed and distributed;
4. From the software point of view, the conversion is simply to improve the IO speed;

If you have to force port the file, consider the following:
1. Mongodb maintenance and disaster recovery require professional developers (If your O & M is successful, I will not mention it ), because many Mongodb configurations require some simple javascript syntax support, it is easier for developers to do so;
2. Mongodb is non-relational. Therefore, when porting a relational database designed to strictly abide by the paradigm, you must consider the efficiency of Multi-table queries. In general, Relational Tables need to be redundant to achieve efficient query. You can only maintain multiple master tables and Relational Tables together with one Data Query table through code. The added Code complexity is obvious.
3. Many features of relational databases are not available in Mongodb. You must consider them before porting them. For example, auto-incrementing primary keys, federated primary keys (which can be replaced by unique indexes), related drivers, and connection methods (I use mssql, so only mssql can be used as an example .);
4. Because Mongodb uses the file storage system of the operating system to operate and maintain the storage media, disk fragments are generated during frequent additions and deletions. (Developers do not have to worry too much about this );
5. Finally, let's talk about Mongodb queries. If your relational database has a lot of Multi-Table connection queries (more than 3), please do not try to transplant them. Otherwise, the performance and efficiency can be maximized only by referring to 2;

Mongodb Problems

As a non-relational database, mongodb is not connected for query. You can add a number of posts field to the collection of user information and update this field each time you insert a post. This ensures query efficiency and mongodb queries are much faster than updates, some redundancy is required for quick query at the cost of insertion performance. The count operation is used in collections with a large amount of data. If many results are met, the efficiency is not very high.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.