How to connect to MongoDB using PhantomJS

烂漫一生 提交于 2019-12-21 19:19:12

问题


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


回答1:


You can use a MongoDB REST client:

  • Sleepy.Mangoose: It's the best IMO

  • 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 server

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).


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).



来源:https://stackoverflow.com/questions/10220487/how-to-connect-to-mongodb-using-phantomjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!