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