Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
 def unlock(self):
     """Unlock a previously locked server.
     """
     cmd = {"fsyncUnlock": 1}
     with self._socket_for_writes() as sock_info:
         if sock_info.max_wire_version >= 4:
             try:
                 sock_info.command("admin", cmd)
             except OperationFailure as exc:
                 # Ignore "DB not locked" to replicate old behavior
                 if exc.code != 125:
                     raise
         else:
             helpers._first_batch(sock_info, "admin", "$cmd.sys.unlock",
                 {}, -1, True, self.codec_options,
                 ReadPreference.PRIMARY, cmd, self._event_listeners)
Exemplo n.º 4
0
    def current_op(self, include_all=False):
        """Get information on operations currently running.

        :Parameters:
          - `include_all` (optional): if ``True`` also list currently
            idle operations in the result
        """
        cmd = SON([("currentOp", 1), ("$all", include_all)])
        with self.__client._socket_for_writes() as sock_info:
            if sock_info.max_wire_version >= 4:
                return sock_info.command("admin", cmd)
            else:
                spec = {"$all": True} if include_all else {}
                x = helpers._first_batch(sock_info, "admin", "$cmd.sys.inprog",
                                         spec, -1, True, self.codec_options,
                                         ReadPreference.PRIMARY, cmd, self.client._event_listeners)
                return x.get('data', [None])[0]
Exemplo n.º 5
0
    def current_op(self, include_all=False):
        """Get information on operations currently running.

        :Parameters:
          - `include_all` (optional): if ``True`` also list currently
            idle operations in the result
        """
        cmd = SON([("currentOp", 1), ("$all", include_all)])
        with self.__client._socket_for_writes() as sock_info:
            if sock_info.max_wire_version >= 4:
                return sock_info.command("admin", cmd)
            else:
                spec = {"$all": True} if include_all else {}
                x = helpers._first_batch(sock_info, "admin", "$cmd.sys.inprog",
                    spec, -1, True, self.codec_options,
                    ReadPreference.PRIMARY, cmd, self.client._event_listeners)
                return x.get('data', [None])[0]
 def _list_collections(self, sock_info, slave_okay, criteria=None):
     """Internal listCollections helper."""
     criteria = criteria or {}
     if sock_info.max_wire_version > 2:
         cmd = SON([("listCollections", 1), ("cursor", {})])
         if criteria:
             cmd["filter"] = criteria
         coll = self["$cmd"]
         cursor = self._command(sock_info, cmd, slave_okay)["cursor"]
     else:
         coll = self["system.namespaces"]
         res = _first_batch(sock_info, coll.full_name,
                            criteria, 0, slave_okay,
                            CodecOptions(), ReadPreference.PRIMARY)
         cursor = {
             "id": res["cursor_id"],
             "firstBatch": res["data"],
             "ns": coll.full_name,
         }
     return CommandCursor(coll, cursor, sock_info.address)
Exemplo n.º 7
0
 def _list_collections(self, sock_info, slave_okay, criteria=None):
     """Internal listCollections helper."""
     criteria = criteria or {}
     if sock_info.max_wire_version > 2:
         cmd = SON([("listCollections", 1), ("cursor", {})])
         if criteria:
             cmd["filter"] = criteria
         coll = self["$cmd"]
         cursor = self._command(sock_info, cmd, slave_okay)["cursor"]
     else:
         coll = self["system.namespaces"]
         res = _first_batch(sock_info,
                            coll.full_name, criteria, 0, slave_okay,
                            CodecOptions(), ReadPreference.PRIMARY)
         cursor = {
             "id": res["cursor_id"],
             "firstBatch": res["data"],
             "ns": coll.full_name,
         }
     return CommandCursor(coll, cursor, sock_info.address)