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