Home Database Mysql Tutorial mongodb实现关系型数据库中查询某一列的效果

mongodb实现关系型数据库中查询某一列的效果

Jun 07, 2016 pm 03:58 PM
mongodb Relational accomplish Effect database Inquire

最近在tornado\mongodb\ansible mongodb中有个find()方法很牛逼,可以将集合中所有的表都传出来,一开始我这么写 class Module_actionHandler(tornado.web.RequestHandler): def get(self, *args, **kwargs): coll = self.application.db.waitfish hosts = col

最近在tornado\mongodb\ansible

mongodb中有个find()方法很牛逼,可以将集合中所有的表都传出来,一开始我这么写

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,
        )
Copy after login
然后在模板中:
<select name="hostname">
                {% for host in hosts %}
                <option name="{{ host[&#39;hostname&#39;] }}" >{{ host[&#39;hostname&#39;] }}</option>
                {% end %}
</select>
Copy after login
后来想了想find()方法是找出所有的表,这太伤不起了..

于是又去看了度娘,基本上都是列出一大堆查询命令,好多中方法的.

最后我还是选了这一种:

class Module_actionHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        coll = self.application.db.waitfish
        hosts = coll.find({}, {&#39;hostname&#39;:1,"_id":0})#解释一下,这里hostname:1 表示返回hostname列,由于_id列每次都返回所以用0禁用掉,模板还一样
        modulenames = [&#39;ping&#39;, &#39;setup&#39;, &#39;copy&#39;]
        self.render(
            "module_action.html",
            hosts = hosts,
            modulenames = modulenames,
        )
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers. Apr 23, 2024 am 08:04 AM

Easily understand 4K HD images! This large multi-modal model automatically analyzes the content of web posters, making it very convenient for workers.

The screen is good for playing games. Brief analysis of iQOO Neo9S Pro+ screen The screen is good for playing games. Brief analysis of iQOO Neo9S Pro+ screen Jul 19, 2024 pm 03:53 PM

The screen is good for playing games. Brief analysis of iQOO Neo9S Pro+ screen

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

OPPO Find X7 is a masterpiece! Capture your every moment with images OPPO Find X7 is a masterpiece! Capture your every moment with images Aug 07, 2024 pm 07:19 PM

OPPO Find X7 is a masterpiece! Capture your every moment with images

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

What to do if navicat expires What to do if navicat expires Apr 23, 2024 pm 12:12 PM

What to do if navicat expires

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

How to handle database connection errors in PHP

See all articles