From fc7c30a3b0e9f9db2d7260f32bb80d26d0cf98e1 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 10 Dec 2024 16:15:52 +0200 Subject: [PATCH 1/2] Update MongoDB docs on permissions and postImages. --- installation/database-setup.mdx | 55 +++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/installation/database-setup.mdx b/installation/database-setup.mdx index 6c4a9ab0..a10e774b 100644 --- a/installation/database-setup.mdx +++ b/installation/database-setup.mdx @@ -348,11 +348,60 @@ Notably, some "serverless Postgres" providers do not support logical replication **Version compatibility**: PowerSync requires MongoDB version 6.0 or greater. -PowerSync requires the `find` and `changeStream` permissions on all databases and collections. +### Permissions required - MongoDB Atlas -PowerSync also requires `createCollection`, `insert`, `update`, and `remove` permissions to the `_powersync_checkpoints` collection. +For MongoDB Atlas databases, the minimum permissions are: -For MongoDB Atlas users, PowerSync requires `readWrite@mydb._powersync_checkpoints` and `readAnyDatabase@admin` +``` +readWrite@._powersync_checkpoints +read@ +``` + +To allow PowerSync to automatically configure enable `changeStreamPreAndPostImages` on +replicated collections, instead use: + +``` +dbAdmin@ +``` + +If you are replicating from multiple databases in the cluster, you need read permissions on the entire cluster: + +``` +readAnyDatabase@admin +``` + + +### Permissions required - Self-hosted + +For self-hosted MongoDB, PowerSync requires the `find` and `changeStream` permissions on the database being replicated. + +PowerSync also requires `createCollection`, `dropCollection`, `insert`, `update`, and `remove` permissions to the `_powersync_checkpoints` collection. + +### postImages + +To replicate data from MongoDB to PowerSync in a consistent manner, PowerSync +uses Change Streams with `fullDocument: 'required'` to get postImages with every change. +For this to work, `changeStreamPreAndPostImages` must be enabled on every replicated collection. + +A PowerSync instance can be configured to enable this automatically, if it has +sufficient permissions (see permissions above). Alternatively, run this on every collection: + +```js +db.runCommand({ + collMod: COLLECTION_NAME, + changeStreamPreAndPostImages: { enabled: true } +}) +``` + +You can view which collections have the option enabled using: + +```js +db.getCollectionInfos().filter(c => c.options?.changeStreamPreAndPostImages?.enabled) +``` + +A PowerSync instance can alternative be configured to replicate using `fullDocument: 'updateLookup'`. +This was the default for older instances. However, this may lead to consistency issues, +so we strongly recommend enabling postImages support instead. ## MySQL (Alpha) From 729777c5d2b14fe88a930cbf4c1120fb6b942a46 Mon Sep 17 00:00:00 2001 From: benitav Date: Wed, 11 Dec 2024 08:56:56 +0200 Subject: [PATCH 2/2] Update installation/database-setup.mdx --- installation/database-setup.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/database-setup.mdx b/installation/database-setup.mdx index a10e774b..64c30c17 100644 --- a/installation/database-setup.mdx +++ b/installation/database-setup.mdx @@ -399,7 +399,7 @@ You can view which collections have the option enabled using: db.getCollectionInfos().filter(c => c.options?.changeStreamPreAndPostImages?.enabled) ``` -A PowerSync instance can alternative be configured to replicate using `fullDocument: 'updateLookup'`. +A PowerSync instance can alternatively be configured to replicate using `fullDocument: 'updateLookup'`. This was the default for older instances. However, this may lead to consistency issues, so we strongly recommend enabling postImages support instead.