From 4c013859efa20cc2e896ce380cd38ce7eea6bc34 Mon Sep 17 00:00:00 2001 From: Rae Mac <633012+okdistribute@users.noreply.github.com> Date: Mon, 23 May 2022 15:33:57 -0700 Subject: [PATCH] Update snippets --- docs/concepts/syncing-data.mdx | 2 +- snippets.json | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/concepts/syncing-data.mdx b/docs/concepts/syncing-data.mdx index c5c49eb4cb..fdaec33a13 100644 --- a/docs/concepts/syncing-data.mdx +++ b/docs/concepts/syncing-data.mdx @@ -1,6 +1,6 @@ --- title: 'Syncing Data' -sidebar_position: 6 +sidebar_position: 7 --- import Tabs from '@theme/Tabs'; diff --git a/snippets.json b/snippets.json index 2bbe61be9f..3745af5d1f 100644 --- a/snippets.json +++ b/snippets.json @@ -15,7 +15,7 @@ "counter": "let collection = ditto.store().collection(\"people\").unwrap();\nlet doc_id = collection\n .upsert(json!({\"name\": \"Frank\", \"owned_cars\": 0}))\n .unwrap();\n\ncollection\n .find_by_id(doc_id)\n .update(|x| {\n if let Some(doc) = x {\n doc.replace_with_counter(\"owned_cars\", false).unwrap();\n doc.increment(\"owned_cars\", 1.0).unwrap();\n }\n })\n .unwrap();\n\n", "array": "let people = ditto.store().collection(\"people\").unwrap();\nlet id = people\n .upsert(json!({\"name\": \"Frank\", \"friends\": []}))\n .unwrap();\n\npeople\n .find_by_id(id)\n .update(|opt_doc| {\n if let Some(doc) = opt_doc {\n doc.push(\"friends\", \"Susan\").unwrap();\n }\n })\n .unwrap();\n\n", "update": "let collection = ditto.store().collection(\"people\").unwrap();\nlet doc_id = collection\n .upsert(json!({\"name\": \"Frank\", \"owned_cars\": 0, \"friends\": []}))\n .unwrap();\n\ncollection\n .find_by_id(doc_id)\n .update(|opt_doc| {\n if let Some(doc) = opt_doc {\n doc.set(\"age\", 32).unwrap();\n doc.replace_with_counter(\"owned_cars\", false).unwrap();\n doc.increment(\"owned_cars\", 1.0).unwrap();\n doc.push(\"friends\", \"Susan\").unwrap();\n }\n })\n .unwrap();\n\n", - "query-basic": "collection\n .find(\"favoriteBooks[0].title == \\'The Great Gatsby\\'\")\n .exec()?;\n\n", + "query-basic": "collection\n .find(\"favoriteBook.title == \\'The Great Gatsby\\'\")\n .exec()?;\n\n", "query-args": "let args = json!({\"name\": \"Susan\", \"age\": 32});\ncollection\n .find_with_args(\"name == $args.name && arg <= $args.age\", args)\n .exec()?;\n\n", "query-sort": "let sort_param = ffi_sdk::COrderByParam {\n query_c_str: c!(\"miles\"),\n direction: ffi_sdk::QuerySortDirection::Ascending,\n};\ncollection\n .find(\"color == \\'red\\'\")\n .sort(vec![sort_param])\n .exec()?;\n\n", "query-limit": "let sort_param = ffi_sdk::COrderByParam {\n query_c_str: c!(\"rank\"),\n direction: ffi_sdk::QuerySortDirection::Ascending,\n};\ncollection\n .find(\"color == \\'red\\'\")\n .sort(vec![sort_param])\n .limit(100)\n .exec()?;\n\n", @@ -37,7 +37,7 @@ "upsert-composite-primary-key": "DITDocumentID *docID = [[ditto.store collection:@\"people\"]\n upsert:@{\n @\"_id\": @{ @\"userId\": @\"456abc\", @\"workId\": @789 },\n @\"name\": @\"John\",\n @\"age\": @31 }\n error:nil];\nNSLog(@\"%@\", docID); // => \"NSDictionary @{ @\"userId\": \"456abc\": @\"workId\": @789 }\"\n\n", "upsert-datatypes": "[[ditto.store collection:@\"foo\"]\n upsert:@{\n @\"boolean\": @true,\n @\"string\": @\"Hello World\",\n @\"number\": @10,\n @\"map\": @{ @\"key\": @\"value\" },\n @\"array\": @[ @1, @2, @3 ],\n @\"null\": [NSNull null]\n }\n error:nil\n];\n\n", "upsert-default-data": "DITDocumentID *defaultDocID = [[ditto.store collection:@\"people\"]\n upsert:@{ @\"name\": @\"Susan\", @\"age\": @31 }\n writeStrategy: DITWriteStrategyInsertDefaultIfAbsent\n error:nil];\n\n", - "query-basic": "NSArray *docs = [[[ditto.store collection:@\"people\"]\n find:@\"favoriteBooks[0].title == 'The Great Gatsby'\"] exec];\n\n", + "query-basic": "NSArray *docs = [[[ditto.store collection:@\"people\"]\n find:@\"favoriteBook.title == 'The Great Gatsby'\"] exec];\n\n", "query-args": "NSArray *documents = [[[ditto.store collection:@\"people\"] find:@\"name == $args.name && age <= $args.age\" withArgs:@{@\"age\": @32, @\"name\": @\"Max\"}] exec];\n\n", "remove-query": "NSArray *removedIDs = [[[ditto.store collection:@\"people\"]\n find:@\"name == 'Susan'\"] remove];\n\n", "remove-id": "[[[ditto.store collection:@\"test\"] findByID:docID] remove];\n\n", @@ -46,6 +46,7 @@ "query-sort": "NSArray *sortedRedCars = [[[[ditto.store collection:@\"cars\"]\n find:@\"color == 'red'\"]\n sort:@\"miles\" direction:DITSortDirectionAscending] exec];\n\n", "query-limit": "NSArray *sortedAndLimitedRedCars = [[[[[ditto.store collection:@\"cars\"]\n find:@\"color == 'red'\"]\n sort:@\"miles\" direction:DITSortDirectionAscending]\n limit:100] exec];\n\n", "sync-basic": "\n DITDitto *ditto = [TestHelpers makeDitto];\n\n NSError *error = nil;\n [ditto tryStartSync:&error];\n\n", + "write-transaction": "NSArray *results = [store write:^(DITWriteTransaction *tx) {\n DITScopedWriteTransaction *cars = tx[@\"cars\"];\n DITScopedWriteTransaction *people = tx[@\"people\"];\n NSString *docId = @\"abc123\";\n [people upsert:@[@{@\"_id\": docId}, @{@\"name\": @\"Susan\"}] error:nil];\n [cars upsert:@[@{@\"make\": @\"Ford\"}, @{@\"color\": @\"black\"}, @{@\"owner\": docId}] error:nil];\n [cars upsert:@[@{@\"make\": @\"Toyota\"}, @{@\"color\": @\"red\"}, @{@\"owner\": docId}] error:nil];\n /*\n try! cars.upsert([\"make\": \"Ford\", \"color\": \"red\", \"owner\": docId])\n try! cars.upsert([\"make\": \"Toyota\", \"color\": \"black\", \"owner\": docId])\n people.findByID(docId).evict()\n */\n}];\n\n", "sync-observe": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observe:^(NSArray *docs, DITLiveQueryEvent *event) {\n\n}];\n\n", "subscribe": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"] subscribe];\n\n", "sync-observe-local": "\nDITDitto *ditto = [TestHelpers makeDitto];\n// Register live query to update UI\nDITCollection *collection = [ditto.store collection:@\"cars\"];\n\nDITLiveQuery *liveQuery = [[collection find:@\"color == 'red'\"]\n observeLocal:^(NSArray *docs, DITLiveQueryEvent *event) {\n\n}];\n\n", @@ -59,6 +60,7 @@ }, "swift": { "shared-key": "// This is just an example. You should use OpenSSL to generate a unique shared key for every application.\nlet p256DerB64 = \"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFUUrOkOH52QN+Rr6uDSDsk4hUTcD1eW4mT0UnGGptFehRANCAATJ3fG8TVLQcDwUV18BJJI8efK0hQAjzB3VJeYOVbfOlqnfukVId0V25r/abxwjD3HfHuPsCGEiefzzmkMbjPo9\"\nlet identity = DittoIdentity.sharedKey(appID: \"app\", sharedKey: p256DerB64)\nDitto(identity: identity)\n\n", + "write-transaction": "ditto.store.write { tx in\n let cars = tx.scoped(toCollectionNamed: \"cars\")\n let people = tx.scoped(toCollectionNamed: \"people\")\n let docId = \"abc123\"\n try! people.upsert([\"_id\": docId, \"name\": \"Susan\"])\n try! cars.upsert([\"make\": \"Ford\", \"color\": \"red\", \"owner\": docId])\n try! cars.upsert([\"make\": \"Toyota\", \"color\": \"black\", \"owner\": docId])\n people.findByID(docId).evict()\n}\n\n", "online-playground": "let ditto = Ditto(identity: DittoIdentity.onlinePlaygroundV2(\n // Replace the all-zero app ID with your own app ID\n appID: \"00000000-0000-4000-0000-000000000000\",\n token: \"REPLACE_ME_WITH_A_SHARED_TOKEN\")\n)\ntry! ditto.tryStartSync()\n\n", "datamodel": "let carsCollection = ditto.store[\"cars\"]\n// or\nlet carsCollection = ditto.store.collection(\"cars\")\n\n", "attachment": "\nlet collection = ditto.store[\"foo\"]\n\nlet myImageURL = bundle.url(forResource: \"image\", withExtension: \"png\")!\n\nlet metadata = [\"name\": \"my_image.png\"]\nlet attachment = collection.newAttachment(\n path: myImageURL.path,\n metadata: metadata\n)!\n\nlet docID = try! collection.upsert([\"some\": \"string\", \"my_attachment\": attachment])\n\n// Later, find the document and the fetch the attachment\n\nlet doc = collection.findByID(docID).exec()\nlet attachmentToken = doc![\"my_attachment\"].attachmentToken!\n\nlet fetcher = collection.fetchAttachment(token: attachmentToken) { status in\n switch status {\n case .completed(let fetchedAttachment):\n // Do something with attachment\n break\n default:\n print(\"Unable to fetch attachment\")\n break\n }\n}\n\n", @@ -70,7 +72,7 @@ "update": "let docID = try! ditto.store[\"people\"].upsert([\n \"name\": \"Frank\",\n \"age\": 31,\n \"ownedCars\": 0,\n \"friends\": []\n])\n\nditto.store[\"people\"].findByID(docID).update { mutableDoc in\n mutableDoc?[\"age\"] = 32\n mutableDoc?[\"ownedCars\"].replaceWithCounter()\n mutableDoc?[\"ownedCars\"].increment(amount: 1)\n mutableDoc?[\"friends\"].push(\"Susan\")\n}\n\n", "upsert": "// upsert JSON-compatible data into Ditto\nlet docID = try! ditto.store[\"people\"].upsert([\n \"name\": \"Susan\",\n \"age\": 31\n])\n\n", "upsert-id": "// upsert JSON-compatible data into Ditto\nlet docID = try! ditto.store[\"people\"].upsert([\n \"_id\": \"abc123\",\n \"name\": \"Susan\",\n \"age\": 31\n])\n\n", - "query-basic": "let collection = ditto.store[\"people\"]\n .find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n .exec()\n\n", + "query-basic": "let collection = ditto.store[\"people\"]\n .find(\"favoriteBook.title == 'The Great Gatsby'\")\n .exec()\n\n", "query-args": "let documents = ditto.store[\"users\"].find(\"name == $args.name && age <= $args.age\", args: [\n \"age\": 32,\n \"name\": \"Max\"\n]).exec()\n\n", "query-sort": "let sortedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", direction: .ascending)\n .exec()\n\n", "query-limit": "let sortedAndLimitedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", direction: .ascending)\n .limit(100)\n .exec()\n\n", @@ -102,7 +104,7 @@ "remove-query": "ditto.get_store().collection(\"people\").find(\"age <= 32\").remove();\n\n", "evict": "ditto.get_store().collection(\"people\").find(\"age <= 32\").evict();\n\n", "upsert-default-data": "DocumentId doc_id = ditto.get_store().collection(\"people\").upsert(\n content, WriteStrategy::insertDefaultIfAbsent);\n\n", - "query-basic": "std::vector results =\n ditto.get_store()\n .collection(\"people\")\n .find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n .exec();\n\n", + "query-basic": "std::vector results =\n ditto.get_store()\n .collection(\"people\")\n .find(\"favoriteBook.title == 'The Great Gatsby'\")\n .exec();\n\n", "query-args": "json args = json({{\"age\", 32}, {\"name\", \"max\"}});\nstd::vector big_c_values =\n ditto.get_store()\n .collection(\"people\")\n .find(\"name == $args.name && age <= $args.age\", args)\n .exec();\n\n", "query-sort": "std::vector sorted_red_cars =\n ditto.get_store()\n .collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", SortDirection::ascending)\n .exec();\n\n", "query-limit": "std::vector sorted_and_limited_red_cars =\n ditto.get_store()\n .collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", SortDirection::ascending)\n .limit(100)\n .exec();\n\n", @@ -120,7 +122,7 @@ "upsert-id": "curl -X POST 'https:///api/v1/store' \\\n --header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n --header 'Content-Type: application/json' \\\n --data-raw '{\n \"method\": \"write\",\n \"parameters\": {\n \"commands\": [{\n \"method\": \"upsert\",\n \"collection\": \"people\",\n \"value\": {\n \"_id\": \"456abc\",\n \"name\": \"Susan\", \n \"age\": 31\n }\n }]\n }\n }'\n\n", "upsert-datatypes": "curl -X POST 'https:///api/v1/store' \\\n --header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n --header 'Content-Type: application/json' \\\n --data-raw '{\n \"method\": \"write\",\n \"parameters\": {\n \"commands\": [{\n \"method\": \"upsert\",\n \"collection\": \"people\",\n \"value\": {\n \"_id\": \"456abc\",\n \"boolean\": true, \n \"string\": \"Hello World\",\n \"number\": 10,\n \"map\": {\n \"key\": \"value\",\n },\n \"array\": [1,2,3],\n \"null\": null\n }\n }]\n }\n }'\n\n", "update": "curl -X POST 'https:///api/v1/store' \\\n --header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n --header 'Content-Type: application/json' \\\n --data-raw '{\n \"method\": \"write\",\n \"parameters\": {\n \"commands\": [{\n \"method\": \"upsert\",\n \"collection\": \"people\",\n \"value\": {\n \"_id\": \"123abc\",\n \"name\": \"Frank\", \n \"age\": 32,\n \"friends\": [\"Susan\"],\n \"owned_cars\": 0\n }\n }]\n }\n }'\n\n", - "query-basic": "curl -X POST 'https:///api/v1/store' \\\n--header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n \"method\": \"find\",\n \"parameters\": {\n \"collection\": \"people\",\n \"query\": \"favoriteBooks[0].title == 'The Great Gatsby'\"\n }\n }'\n\n", + "query-basic": "curl -X POST 'https:///api/v1/store' \\\n--header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n \"method\": \"find\",\n \"parameters\": {\n \"collection\": \"people\",\n \"query\": \"favoriteBook.title == 'The Great Gatsby'\"\n }\n }'\n\n", "query-args": "curl -X POST 'https:///api/v1/store' \\\n--header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n \"method\": \"find\",\n \"parameters\": {\n \"args\": {\n \"name\": \"max\",\n \"age\": 32\n },\n \"collection\": \"people\",\n \"query\": \"name == $args.name && age <= $args.age\"\n }\n }'\n\n", "query-limit": "curl -X POST 'https:///api/v1/store' \\\n --header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n --header 'Content-Type: application/json' \\\n --data-raw '{\n \"method\": \"find\",\n \"parameters\": {\n \"collection\": \"people\",\n \"query\": \"color == 'red'\",\n \"limit\": 100\n }\n }'\n\n", "remove-id": "curl -X DELETE 'https:///api/v1/collections/people/documents/' \\\n --header 'X-DITTO-CLIENT-ID: AAAAAAAAAAAAAAAAAAAABQ==' \\\n --header 'Content-Type: application/json' \n\n" @@ -136,7 +138,7 @@ "upsert-composite-primary-key": "const docId = await ditto.store.collection('people').upsert({\n _id: { userId: '456abc', workId: 789 },\n name: 'Susan',\n age: 31,\n})\nconsole.log(docId) // \"{ \"userId\": \"456abc\", \"workId\": 789 }\"\n\n", "array": "const id = await ditto.store.collection('people').upsert({\n name: 'Frank',\n friends: [],\n})\n\nawait ditto.store\n .collection('people')\n .findByID(id)\n .update((mutableDoc) => {\n mutableDoc['friends'].push('Susan')\n })\n\n", "update": "const docID = await ditto.store.collection('people').upsert({\n name: 'Frank',\n age: 31,\n ownedCars: 0,\n friends: [],\n})\n\nawait ditto.store\n .collection('people')\n .findByID(docID)\n .update((mutableDoc) => {\n mutableDoc['age'] = 32\n mutableDoc['friends'].push('Susan')\n\n mutableDoc._replaceWithCounterAt('ownedCars')\n mutableDoc._incrementCounterAt('ownedCars', 1)\n })\n\n", - "query-basic": "const collection = await ditto.store.collection('people').find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n\n", + "query-basic": "const collection = await ditto.store.collection('people').find(\"favoriteBook.title == 'The Great Gatsby'\")\n\n", "remove-id": "await ditto.store.collection('people').findByID(docId).remove()\n\n", "query-args": "const query = 'name == $args.name && age <= $args.age'\nconst documents = await ditto.store.collection('people').find(query, {\n age: 32,\n name: 'Max',\n})\n\n", "remove-query": "await ditto.store.collection('people').find('age <= 32').remove()\n\n", @@ -170,7 +172,7 @@ "upsert-datatypes": "// Insert JSON-compatible data into Ditto\nvar content = new Dictionary\n{\n { \"boolean\", true },\n { \"string\", \"Hello World\" },\n { \"number\", 10 },\n { \"map\", new Dictionary{{ \"key\", \"value\"}} },\n { \"array\", new int[] {1, 2, 3} },\n { \"null\", null }\n};\nditto.Store.Collection(\"foo\").Upsert(content);\n\n", "online-playground": "try\n{\n var ditto = new Ditto(DittoIdentity.OnlinePlaygroundV2(\"00000000-0000-4000-0000-000000000000\", \"REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN\"));\n ditto.TryStartSync();\n}\ncatch (DittoException ex)\n{\n System.Console.WriteLine($\"Ditto Error {ex.Message}\");\n}\n\n", "shared-key": "// This is just an example. You should use OpenSSL to generate a unique shared key for every application.\nstring p256DerB64 = \"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFUUrOkOH52QN+Rr6uDSDsk4hUTcD1eW4mT0UnGGptFehRANCAATJ3fG8TVLQcDwUV18BJJI8efK0hQAjzB3VJeYOVbfOlqnfukVId0V25r/abxwjD3HfHuPsCGEiefzzmkMbjPo9\";\nvar identity = DittoIdentity.SharedKey(\"app\", p256DerB64);\nDitto ditto = new Ditto(identity);\n\n", - "query-basic": "var results = ditto.Store.Collection(\"people\")\n .Find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n .Exec();\n\n", + "query-basic": "var results = ditto.Store.Collection(\"people\")\n .Find(\"favoriteBook.title == 'The Great Gatsby'\")\n .Exec();\n\n", "query-args": "var docs = ditto.Store\n .Collection(\"users\")\n .Find(\n \"name == $args.name && age <= $args.age\",\n new Dictionary { { \"name\", \"max\" }, { \"age\", 32 } })\n .Exec();\n\n", "query-sort": "var sortedCars = ditto.Store.Collection(\"cars\")\n .Find(\"color == 'red'\")\n .Sort(\"miles\", direction: DittoSortDirection.Ascending)\n .Exec();\n\n", "query-limit": "var sortedAndLimitedRedCars = ditto.Store.Collection(\"cars\")\n .Find(\"color == 'red'\")\n .Sort(\"miles\", direction: DittoSortDirection.Ascending)\n .Limit(100).Exec();\n\n", @@ -188,12 +190,13 @@ "upsert": "val docID = ditto.store[\"people\"].upsert(\n mapOf(\n \"name\" to \"Susan\",\n \"age\" to 31\n )\n)\n\n", "upsert-composite-primary-key": "val docId = ditto.store[\"people\"].upsert(\n mapOf(\n \"_id\" to mapOf( \"userId\" to \"456abc\", \"workId\" to 789),\n \"name\" to \"Susan\",\n \"age\" to 31\n )\n)\n\n", "upsert-datatypes": "ditto.store[\"foo\"].upsert(mapOf(\n \"boolean\" to true,\n \"string\" to \"Hello World\",\n \"number\" to 10,\n \"map\" to mapOf(\"key\" to \"value\"),\n \"array\" to listOf(1,2,3),\n \"null\" to null\n))\n\n", + "write-transaction": "val results = ditto.store.write { tx ->\n val cars = tx.scoped(\"cars\")\n val people = tx.scoped(\"people\")\n val docID = \"abc123\"\n people.upsert(mapOf(\"_id\" to docID, \"name\" to \"Susan\"))\n cars.upsert(mapOf(\"make\" to \"Hyundai\", \"color\" to \"red\", \"owner\" to docID))\n cars.upsert(mapOf(\"make\" to \"Jeep\", \"color\" to \"pink\", \"owner\" to docID))\n people.findByID(DittoDocumentID(docID)).evict()\n}\n\n", "counter": "val docID = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"ownedCars\" to 0\n))\n\nditto.store.collection(\"people\").findByID(docID).update { mutableDoc ->\n mutableDoc!![\"ownedCars\"].replaceWithCounter()\n mutableDoc[\"ownedCars\"].increment(1)\n}\n\n", "array": "val id = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"friends\" to emptyList()\n))\n\nval susanId = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Susan\",\n \"friends\" to emptyList()\n))\n\nditto.store.collection(\"people\").findByID(id).update { mutableDoc ->\n mutableDoc!![\"friends\"].push(susanId)\n}\n\n", "update": "val frankId = ditto.store[\"people\"].upsert(mapOf(\n \"name\" to \"Frank\",\n \"age\" to 31,\n \"ownedCars\" to 0,\n \"friends\" to emptyList()\n))\n\nditto.store.collection(\"people\").findByID(frankId).update { mutableDoc ->\n mutableDoc?.let {\n it[\"age\"].set(32)\n it[\"ownedCars\"].replaceWithCounter()\n it[\"ownedCars\"].increment(1)\n it[\"friends\"].push(susanId)\n }\n}\n\n", "evict": "ditto.store[\"people\"].find(\"age <= 32\").evict()\n\n", "upsert-default-data": "val docId = ditto.store.collection(\"people\").upsert(mapOf(\n \"name\" to \"Susan\",\n \"age\" to 31\n), DittoWriteStrategy.InsertDefaultIfAbsent)\n\n", - "query-basic": "val results = ditto.store.collection(\"people\")\n .find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n .exec()\n\n", + "query-basic": "val results = ditto.store.collection(\"people\")\n .find(\"favoriteBook.title == 'The Great Gatsby'\")\n .exec()\n\n", "query-args": "val foundDocs = ditto.store.collection(\"people\")\n .find(\"name == \\$args.name && age <= \\$args.age\", mapOf(\"name\" to \"max\", \"age\" to 32))\n\n", "query-sort": "val sortedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", DittoSortDirection.Ascending)\n .exec()\n\n", "query-limit": "val sortedAndLimitedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", DittoSortDirection.Ascending)\n .limit(100)\n .exec()\n\n", @@ -224,7 +227,7 @@ "array": "Map frank = new HashMap<>();\nfrank.put(\"name\", \"Frank\");\nfrank.put(\"friends\", Arrays.asList());\nDittoDocumentID frankId = ditto.store.collection(\"people\").upsert(frank);\n\nditto.store.collection(\"people\").findByID(frankId).update(doc -> {\n try {\n doc.get(\"age\").set(32);\n doc.get(\"cars\").push(\"Ford\");\n } catch (DittoError err) {\n // Do something with error\n }\n});\n\n", "update": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Frank\");\ncontent.put(\"age\", 31);\ncontent.put(\"ownedCars\", 0);\ncontent.put(\"friends\", Arrays.asList());\nDittoDocumentID docId = ditto.store.collection(\"people\").upsert(content);\n\nditto.store.collection(\"people\").findByID(docId).update(doc -> {\n try {\n doc.get(\"age\").set(32);\n doc.get(\"ownedCars\").replaceWithCounter();\n doc.get(\"ownedCars\").increment(1);\n doc.get(\"friends\").push(\"Susan\");\n } catch (DittoError err) {\n // Do something with error\n }\n});\n\n", "upsert-default-data": "Map content = new HashMap<>();\ncontent.put(\"name\", \"Susan\");\ncontent.put(\"age\", 31);\nDittoDocumentID docId = ditto.store\n .collection(\"people\")\n .upsert(content, DittoWriteStrategy.InsertDefaultIfAbsent);\n\n", - "query-basic": "List results = ditto.store.collection(\"people\")\n .find(\"favoriteBooks[0].title == 'The Great Gatsby'\")\n .exec();\n\n", + "query-basic": "List results = ditto.store.collection(\"people\")\n .find(\"favoriteBook.title == 'The Great Gatsby'\")\n .exec();\n\n", "query-args": "Map queryArgs = new HashMap<>();\nqueryArgs.put(\"name\", \"max\");\nqueryArgs.put(\"age\", 32);\n\nList foundDocs = ditto.store.collection(\"users\")\n .find(\"name == $args.name && age <= $args.age\", queryArgs)\n .exec();\n\n", "query-sort": "List sortedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", DittoSortDirection.Ascending)\n .exec();\n\n", "query-limit": "List sortedAndLimitedRedCars = ditto.store.collection(\"cars\")\n .find(\"color == 'red'\")\n .sort(\"miles\", DittoSortDirection.Ascending)\n .limit(100)\n .exec();\n\n",