如何使用PhantomJS连接到MongoDB [英] How to connect to MongoDB using PhantomJS

查看:65
本文介绍了如何使用PhantomJS连接到MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行OSX.以为我可以在某个地方找到文档,但是找不到.

I'm Running OSX. Thought I could find documentation somewhere, but could not.

推荐答案

可以使用MongoDB REST客户端:

You can use a MongoDB REST client:

MongoDB REST :看起来很有希望,但是

MongoDB REST: It looks promising, but is not complete yet and has some weird bugs (for example, it refused to send large requests (more than 80,000 characters) and it took me 3 hours to find what was wrong with it)

MongoDB Java REST服务器

您可以从注入的javascript直接连接到其余服务器(使用jQuery的ajax方法或简单地使用xmlhttprequest),但是我认为最好在PhantomJS的evaluate方法中进行操作(因为如果您的页面'解析中出现javascript错误,您注入的javascript可能无法正常运行.

You can connect directly to the rest server from you injected javascript (use jQuery's ajax method or simply use xmlhttprequest), but I think it's better to do it inside PhantomJS's evaluate method (because if the page you're parsing has javascript errors, your the injected javascript might not work properly).

但是我个人不喜欢PhantomJS的REST服务器的想法.我认为最好在 NodeJS 中编写整个应用程序,然后使用 MongoDB Native节点驱动程序,其速度可能比REST服务器快很多倍(因为它不需要JSON HTTP序列化/反序列化,等等).

But I personally don't like the idea of a REST server for PhantomJS. I think It's better to write your whole application in NodeJS and use phantomjs module to run PhantomJS. This way, you don't have to go the REST way and can use the (now official) MongoDB Native Node Driver, which is potentially many times faster than the REST servers (because it doesn't require JSON HTTP serialization/deserialization, among other things).

这篇关于如何使用PhantomJS连接到MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆