MongoDB implements the effect of querying a column in a relational database

Source: Internet
Author: User

Recently in Tornado\mongodb\ansible


There is a find () method in MongoDB that can send out all the tables in the collection, which I wrote at first.


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[' hos Tname ']}}</option>                {% End%}</select>

And then I thought about it. The find () method is to find all the tables, which is too hurtful.

So went to see the degree Niang, basically are listed a lot of query commands, a lot of methods.

In the end, 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}) #解释一下, here hostname:1 means return hostname column, because _ The ID column is returned every time so with 0 disabled, the template is also the same        modulenames = [' ping ', ' setup ', ' Copy ']        self.render (            "module_action.html",            hosts = hosts,            modulenames = Modulenames,        )


MongoDB implements the effect of querying a column in a relational database

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.