(ns)
| 190 | |
| 191 | |
| 192 | def preload_database(ns): |
| 193 | gen.generator_options.numeric_fieldnames = ns['no_numeric_fieldnames'] |
| 194 | gen.generator_options.test_nulls = ns['no_nulls'] |
| 195 | |
| 196 | instance = random.random() |
| 197 | |
| 198 | client = pymongo.MongoClient(ns['host'], ns['port']) |
| 199 | if (ns['collection'] == ''): |
| 200 | collection = client['test']['performance' + str(instance)[2:]] |
| 201 | else: |
| 202 | collection = client['test'][ns['collection']] |
| 203 | |
| 204 | collection.remove() |
| 205 | |
| 206 | i = 0 |
| 207 | while i < ns['number']: |
| 208 | docs = [] |
| 209 | for j in range(0, min(100, ns['number'] - i)): |
| 210 | i += 1 |
| 211 | if ns['big_documents']: |
| 212 | doc = d.copy() |
| 213 | else: |
| 214 | doc = gen.random_document(False) |
| 215 | doc["boo"] = i |
| 216 | doc["_id"] = str(i) |
| 217 | docs.append(doc) |
| 218 | collection.insert(docs, safe=False) |
| 219 | print "Inserted " + str(i) |
| 220 | |
| 221 | # collection.insert(docs) |
| 222 | |
| 223 | # print [i for i in collection.find()] |
| 224 | print "Inserted " + str(ns['number']) + " documents" |
| 225 | print "Database: test" |
| 226 | print "Collection: " + ('performance' + str(instance)[2:] if ns['collection'] == '' else ns['collection']) |
| 227 | |
| 228 | |
| 229 | if __name__ == "__main__": |
no test coverage detected