Esempio n. 1
0
 def array_add_first(self, client, key = '', path = '', value = None, xattr=None, create_parents=None):
     try:
         new_path = self.generate_path(self.nesting_level, path)
         if self.is_sdk_client:
             client.mutate_in(key, SD.array_prepend(new_path, value, xattr=xattr, create_parents=create_parents))
         else:
             client.array_push_first_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_first(self, client, key='', path='', value=None):
     try:
         if self.verbose_func_usage:
             self.log.info(" array_add_first ----> {0} :: {1}".format(path, value))
         if self.use_sdk_client:
             client.mutate_in(key, SD.array_prepend(path, value, xattr=self.xattr))
         else:
             client.array_push_first_sd(key, path, value)
     except Exception:
         raise
 def array_add_first(self, client, key = '', path = '', value = None):
     try:
         if self.verbose_func_usage:
             self.log.info(" array_add_first ----> {0} :: {1}".format(path, value))
         if self.use_sdk_client:
             client.mutate_in(key, SD.array_prepend(path, value, xattr=self.xattr))
         else:
             client.array_push_first_sd(key, path, value)
     except Exception:
         raise
 def array_add_first(self, client, key = '', path = '', value = None, xattr=None, create_parents=None):
     try:
         new_path = self.generate_path(self.nesting_level, path)
         if self.is_sdk_client:
             client.mutate_in(key, SD.array_prepend(new_path, value, xattr=xattr, create_parents=create_parents))
         else:
             client.array_push_first_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 test_multi_value(self):
        cb = self.cb
        key = self.gen_key('sdArray')

        cb.upsert(key, {'array': []})
        cb.mutate_in(key, SD.array_append('array', True))
        self.assertEqual([True], cb.retrieve_in(key, 'array')[0])

        cb.mutate_in(key, SD.array_append('array', 1, 2, 3))
        self.assertEqual([True, 1, 2, 3], cb.retrieve_in(key, 'array')[0])

        cb.mutate_in(key, SD.array_prepend('array', [42]))
        self.assertEqual([[42], True, 1, 2, 3], cb.retrieve_in(key, 'array')[0])
Esempio n. 6
0
    def test_multi_value(self):
        cb = self.cb
        key = self.gen_key('sdArray')

        cb.upsert(key, {'array': []})
        cb.mutate_in(key, SD.array_append('array', True))
        self.assertEqual([True], cb.retrieve_in(key, 'array')[0])

        cb.mutate_in(key, SD.array_append('array', 1, 2, 3))
        self.assertEqual([True, 1, 2, 3], cb.retrieve_in(key, 'array')[0])

        cb.mutate_in(key, SD.array_prepend('array', [42]))
        self.assertEqual([[42], True, 1, 2, 3],
                         cb.retrieve_in(key, 'array')[0])
        "*****@*****.**")))
# end::combine_dict[]

# NOTE:  the mutate_in() operation expects a tuple or list
# tag::array_append[]
collection.mutate_in(
    "customer123", (SD.array_append(
                    "purchases.complete", 777),))

# purchases.complete is now [339, 976, 442, 666, 777]
# end::array_append[]

# tag::array_prepend[]
collection.mutate_in(
    "customer123", [
        SD.array_prepend(
            "purchases.abandoned", 18)])

# purchases.abandoned is now [18, 157, 42, 999]
# end::array_prepend[]

# tag::create_array[]
collection.upsert("my_array", [])
collection.mutate_in("my_array", [SD.array_append("", "some element")])

# the document my_array is now ["some element"]
# end::create_array[]

# tag::add_multi[]
collection.mutate_in(
    "my_array", [
        SD.array_append(
Esempio n. 8
0
----
"""
#tag::arrayappend[]
collection.mutate_in("customer123", SD.array_append("purchases.complete", 777))

# purchases.complete is now [339, 976, 442, 666, 777]
#end::arrayappend[]
"""
----

[source,csharp]
----
"""
#tag::arrayprepend[]
collection.mutate_in("customer123",
                     [SD.array_prepend("purchases.abandoned", 18)])

# purchases.abandoned is now [18, 157, 49, 999]
#end::arrayprepend[]
"""
----

If your document only needs to contain an array, you do not have to create a top-level object wrapper to contain it.
    Simply initialize the document with an empty array and then use the empty path for subsequent sub-document array operations:

    .Creating and populating an array document
                                      [source,csharp]
                                      ----
"""
#tag::createarray[]
collection.upsert("my_array", [])