(self, sock_info, slave_okay, criteria=None)
Internal listCollections helper.
Internal listCollections helper.
Internal listCollections helper .
def _list_collections(self, sock_info, slave_okay, criteria=None):
        """Internal listCollections helper."""
        criteria = criteria or {}
        cmd = SON([("listCollections", 1), ("cursor", {})])
        if criteria:
            cmd["filter"] = criteria

        if sock_info.max_wire_version > 2:
            coll = self["$cmd"]
            cursor = self._command(sock_info, cmd, slave_okay)["cursor"]
            return CommandCursor(coll, cursor, sock_info.address)
        else:
            coll = self["system.namespaces"]
            res = _first_batch(sock_info, coll.database.name, coll.name,
                               criteria, 0, slave_okay,
                               CodecOptions(), ReadPreference.PRIMARY, cmd,
                               self.client._event_listeners)
            data = res["data"]
            cursor = {
                "id": res["cursor_id"],
                "firstBatch": data,
                "ns": coll.full_name,
            }
            # Need to tell the cursor how many docs were in the first batch.
            return CommandCursor(coll, cursor, sock_info.address, len(data))
def _list_collections ( self , sock_info , slave_okay , criteria = None ) : criteria = criteria or { } cmd = SON ( [ ( "listCollections" , 1 ) , ( "cursor" , { } ) ] ) if criteria : cmd [ "filter" ] = criteria if sock_info . max_wire_version > 2 : coll = self [ "$cmd" ] cursor = self . _command ( sock_info , cmd , slave_okay ) [ "cursor" ] return CommandCursor ( coll , cursor , sock_info . address ) else : coll = self [ "system.namespaces" ] res = _first_batch ( sock_info , coll . database . name , coll . name , criteria , 0 , slave_okay , CodecOptions ( ) , ReadPreference . PRIMARY , cmd , self . client . _event_listeners ) data = res [ "data" ] cursor = { "id" : res [ "cursor_id" ] , "firstBatch" : data , "ns" : coll . full_name , } # Need to tell the cursor how many docs were in the first batch. return CommandCursor ( coll , cursor , sock_info . address , len ( data ) )