8 examples of 'pymongo find' in Python

Every line of 'pymongo find' 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
this disclaimer
194def find(collection, limit=0, skip=0, spec=None, fields=None, sort=None):
195 """Find documents in a collection with optional specified values.
197 The `spec` argument is a dictionary of fields and values that should be
198 searched in the collection documents. Only the documents matching will be
199 returned. By default all documents in the collection will be returned.
201 :param collection: The collection where to search.
202 :param limit: How many documents to return, or 0 for not limit.
203 :type int
204 :param skip: How many document to skip from the result.
205 :type int
206 :param spec: A dictionary object with key-value fields to be matched.
207 :type dict
208 :param fields: The fields that should be returned or excluded from the
209 result.
210 :type str, list, dict
211 :param sort: Whose fields the result should be sorted on.
212 :type list
213 :return A list of documents matching the specified values.
214 """
215 return collection.find(
216 spec, fields, limit=limit, skip=skip, sort=sort)

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

38def find1(self, spec=None, callback=None):
39 doc = yield motor.Op(self.collection.find_one, spec)
40 callback(doc)
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)
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)
179def find(cls, *args, **kwargs):
180 return CursorWrapper(cls.collection.find(*args, **kwargs), cls)
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'
313 try:
314 query = _to_dict(query)
315 except Exception, err:
316 return err.message
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
71def find_one_or_404(self, *args, **kwargs):
72 """This method get one document over normal query parameter like
73 :meth:`~flask.ext.mongokit.Document.find_one` but if there no document
74 then it will raise a 404 error.
75 """
77 doc = self.find_one(*args, **kwargs)
78 if doc is None:
79 abort(404)
80 else:
81 return doc
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 = []
50 for r in rs:
51 result.append(r)
53 return result
55 finally:
56 client.close()

Related snippets