def array_add_insert(self, client, key = '', path = '', value = None, xattr=None): try: new_path = self.generate_path(self.nesting_level, path) if self.is_sdk_client: client.mutate_in(key, SD.array_insert(new_path, value, xattr=xattr)) else: client.array_add_insert_sd(key, new_path, json.dumps(value)) except Exception as e: self.log.error(e) self.fail("Unable to add key {0} for path {1} after {2} tries".format(key, path, 1))
def array_add_insert(self, client, key = '', path = '', value = None): try: if self.verbose_func_usage: self.log.info(" array_add_insert ----> {0} :: {1}".format(path, value)) if self.use_sdk_client: client.mutate_in(key, SD.array_insert(path, value, xattr=self.xattr)) else: client.array_add_insert_sd(key, path, value) except Exception: raise
def array_add_insert(self, client, key='', path='', value=None): try: if self.verbose_func_usage: self.log.info(" array_add_insert ----> {0} :: {1}".format(path, value)) if self.use_sdk_client: client.mutate_in(key, SD.array_insert(path, value, xattr=self.xattr)) else: client.array_add_insert_sd(key, path, value) except Exception: raise
"customer123", [ SD.upsert( "purchases.cancelled", [{"Date": "Some date"}])]) try: collection.mutate_in( "customer123", [ SD.array_addunique( "purchases.cancelled", 89)]) except SubdocPathMismatchException: print("Cannot use array_addunique if array contains JSON objs.") # tag::array_insert[] collection.upsert("array", []) collection.mutate_in("array", [SD.array_append("", "hello", "world")]) collection.mutate_in("array", [SD.array_insert("[1]", "cruel")]) # end::array_insert[] # exception raised if attempt to insert in out of bounds position try: collection.mutate_in("array", [SD.array_insert("[6]", "!")]) except PathNotFoundException: print("Cannot insert to out of bounds index.") # can insert into nested arrays as long as the path is appropriate collection.mutate_in("array", [SD.array_append("", ["another", "array"])]) collection.mutate_in("array", [SD.array_insert("[3][2]", "!")]) # tag::counter1[] result = collection.mutate_in("customer123", (SD.counter("logins", 1),))