def collection(self, name) -> 'CollectionReference': from mockfirestore.collection import CollectionReference document = get_by_path(self._data, self._path) new_path = self._path + [name] if name not in document: set_by_path(self._data, new_path, {}) return CollectionReference(self._data, new_path, parent=self)
def collection(self, path: str) -> CollectionReference: path = path.split("/") if len(path) % 2 != 1: raise Exception("Cannot create collection at path {}".format(path)) name = path[-1] if len(path) > 1: current_position = self._ensure_path(path) return current_position.collection(name) else: if name not in self._data: self._data[name] = {} return CollectionReference(self._data, [name])
def collection(self, name: str) -> CollectionReference: if name not in self._data: self._data[name] = {} return CollectionReference(self._data, [name])