view mongo_client.xml @ 3:4d03df88688d draft default tip

Uploaded
author kellrott
date Tue, 24 Jul 2012 17:42:17 -0400
parents bda961c955d5
children
line wrap: on
line source

<tool id="mongo_client" name="Mongo Client" version="1.0.0">
  <description>Mongo Client</description>
  <command interpreter="python">$scriptfile</command>
  <inputs>
	  <param name="server" type="text" size="52" label="Server address"/>
	  <param name="port" type="integer" label="Server Port" value="27017"/>
	  <param name="db" type="text" size="32" label="Database"/>
	  <param name="collection" type="text" size="32" label="Collection"/>
	  <param name="query" type="text" area="True" size="5x25" label="Query">
		<sanitizer>
			<valid initial="string.printable"/>
			<mapping initial="none">
				<add source="&#10;" target="__cn__"/>
				<add source="&quot;" target="__dq__"/>
			</mapping>
		</sanitizer>
	  </param>      
  </inputs>
  <outputs>
      <data name="output" format="txt"/>
  </outputs>
  	<configfiles>

  <configfile name="scriptfile"><![CDATA[#!/usr/bin/env python
import pymongo
import json
import galaxy.eggs
import galaxy.util

query=galaxy.util.restore_text("""$query""")

conn = pymongo.Connection(galaxy.util.restore_text("$server"), $port)
db = conn[galaxy.util.restore_text('$db')]
collection = db[galaxy.util.restore_text('$collection')]

qObj = None
if len(query):
	qObj = json.loads(query)

handle = open(galaxy.util.restore_text("$output"), "w")
for row in collection.find(qObj):
	handle.write("%s\n" % (json.dumps(row)))
handle.close()

]]></configfile>
  	</configfiles>
<help>

Info about the Mongo Query Syntax:
 - `Mongo Query Language &lt;http://www.mongodb.org/display/DOCS/Mongo+Query+Language&gt;`_
 - `Advanced Queries &lt;http://www.mongodb.org/display/DOCS/Advanced+Queries&gt;`_

</help>
</tool>