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 is very cool and can spread out all the tables in the collection.


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

Then I thought about the find () method is to find out all the tables, it is too hurt.

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 to return the 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.