当前位置: 首页>>代码示例>>Python>>正文


Python Connection.command方法代码示例

本文整理汇总了Python中pymongo.connection.Connection.command方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.command方法的具体用法?Python Connection.command怎么用?Python Connection.command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.connection.Connection的用法示例。


在下文中一共展示了Connection.command方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DatastoreMongoStub

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import command [as 别名]

#.........这里部分代码省略.........
      if k != '_id':
        v = self.__create_value_for_mongo_value(document[k])
        entity[k] = v

    pb = entity._ToPb()
    # no decent way to initialize an Entity w/ an existing key...
    if not key.name():
      pb.key().path().element_list()[-1].set_id(key.id())

    return pb

  def __allocate_ids(self, kind, size=None, max=None):
    """Allocates IDs.

    Args:
      kind: A kind.
      size: Number of IDs to allocate.
      max: Upper bound of IDs to allocate.

    Returns:
      Integer as the beginning of a range of size IDs.
    """
    self.__id_lock.acquire()
    ret = None
    col = self.__db.datastore
    _id = 'IdSeq_%s' % kind
    if not col.find_one({'_id': _id}):
      col.insert({'_id': _id, 'next_id': 1})
    if size is not None:
      assert size > 0
      next_id, block_size = self.__id_map.get(kind, (0, 0))
      if not block_size:
        block_size = (size / 1000 + 1) * 1000
        result = self.__db.command(
          "findandmodify",
          "datastore",
          query={"_id": _id},
          update={"$inc": {"next_id": next_id+block_size}})
        next_id = int(result['value']['next_id'])
      if size > block_size:
        result = self.__db.command(
          "findandmodify",
          "datastore",
          query={"_id": _id},
          update={"$inc": {"next_id": size}})
        ret = int(result['value']['next_id'])
      else:
        ret = next_id;
        next_id += size
        block_size -= size
        self.__id_map[kind] = (next_id, block_size)
    else:
      ret = col.find_one({'_id': _id}).get('next_id')
      if max and max >= ret:
        col.update({'_id': _id}, {'$set': {'next_id': max+1}})
    self.__id_lock.release()
    return ret

  def __ValidateAppId(self, app_id):
    """Verify that this is the stub for app_id.

    Args:
      app_id: An application ID.

    Raises:
      datastore_errors.BadRequestError: if this is not the stub for app_id.
开发者ID:fajoy,项目名称:typhoonae,代码行数:70,代码来源:datastore_mongo_stub.py


注:本文中的pymongo.connection.Connection.command方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。