forked from turian/common-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb-field-lengths.py
More file actions
executable file
·24 lines (19 loc) · 953 Bytes
/
mongodb-field-lengths.py
File metadata and controls
executable file
·24 lines (19 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
"""
Print MongoDB field length and field, for every row.
"""
import sys, string
import common.mongodb
import common.json
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-c", "--collection", dest="collection", help="collection name")
parser.add_option("-d", "--database", dest="database", help="database name")
parser.add_option("-f", "--field", dest="field", help="field name")
parser.add_option("-p", "--port", dest="port", help="port number for mongodb", type="int")
parser.add_option("--hostname", dest="hostname", help="hostname for mongodb")
(options, args) = parser.parse_args()
assert options.field is not None
collection = common.mongodb.collection(DATABASE=options.database, name=options.collection, PORT=options.port, HOSTNAME=options.hostname)
for doc in common.mongodb.findall_with_field(collection, field=options.field):
print len(doc[options.field]), repr(doc[options.field])[:1000]