10 examples of 'findall in mongodb' in Python

Every line of 'findall in mongodb' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
31def find(self, col, query=None, fields=None, **kwargs):
32 # TODO batch_size, limit, max_time_ms, sort
33 return self._db[col].find(query, fields, **kwargs)
43def find(self, database, collection, query, limit=50):
44 client = MongoClient(self.host, self.port)
45 try:
46 db = client[database]
47 rs = db[collection].find(query, limit=limit)
48 result = []
49
50 for r in rs:
51 result.append(r)
52
53 return result
54
55 finally:
56 client.close()
117def find(self, index, key, value, mapper=None):
118 cursor = self.cols[index].find({key: value})
119 results = []
120 if mapper:
121 mapper = getattr(Model, mapper)
122 return [mapper(doc) for doc in cursor]
123 else:
124 for doc in cursor:
125 doc['id'] = str(doc.get('_id'))
126 doc.pop('_id')
127 results.append(doc)
128 return results
31@engine
32def find(self, spec=None, count=0, callback=None):
33 cursor = self.collection.find(spec).limit(count)
34 docs = yield motor.Op(cursor.to_list)
35 callback(docs)
62def find_all(self, cls):
63 """Required functionality."""
64 return self._find(cls, {})
33def search_db(collection=None, search_string=None):
34 if search_string is not None:
35 query = re.compile(search_string, re.IGNORECASE)
36
37 if collection == 'movies':
38 return get_results(Movie, {"name" : query},[('name',ASCENDING)])
39 elif collection == 'tv':
40 return get_results(TV, {"name" : query},[('series',ASCENDING)])
41 elif collection == 'books':
42 return get_results(Book, {"name" : query},[('name',ASCENDING)])
43 else:
44 print("Invalid Collection: " + collection)
45 return "Invalid Collection: " + collection
46 else:
47 if collection == 'movies':
48 return get_all(Movie,[('name',ASCENDING)])
49 elif collection == 'tv':
50 return get_all(TV,[('series',ASCENDING)])
51 elif collection == 'books':
52 return get_all(Book,[('name',ASCENDING)])
53 else:
54 print("Invalid Collection: " + collection)
55 return "Invalid Collection: " + collection
37@engine
38def find1(self, spec=None, callback=None):
39 doc = yield motor.Op(self.collection.find_one, spec)
40 callback(doc)
307def find(collection, query=None, user=None, password=None,
308 host=None, port=None, database='admin'):
309 conn = _connect(user, password, host, port)
310 if not conn:
311 return 'Failed to connect to mongo database'
312
313 try:
314 query = _to_dict(query)
315 except Exception, err:
316 return err.message
317
318 try:
319 log.info("Searching for %r in %s", query, collection)
320 mdb = pymongo.database.Database(conn, database)
321 col = getattr(mdb, collection)
322 ret = col.find(query)
323 return list(ret)
324 except pymongo.errors.PyMongoError as err:
325 log.error("Removing objects failed with error: %s", err.message)
326 return err.message
178@classmethod
179def find(cls, *args, **kwargs):
180 return CursorWrapper(cls.collection.find(*args, **kwargs), cls)
47def test_find_int(self):
48 db = self.database
49 db.insert('items', {'foo': 1})
50 db.insert('items', {'foo': 2})
51 docs = db.findall('items', '$foo=?', (1,))
52 assert len(docs) == 1
53 assert docs[0]['foo'] == 1

Related snippets