Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection.watch() error Aborted on React Native SDK #6174

Closed
BondPiyapan opened this issue Oct 5, 2023 · 6 comments
Closed

Collection.watch() error Aborted on React Native SDK #6174

BondPiyapan opened this issue Oct 5, 2023 · 6 comments
Labels

Comments

@BondPiyapan
Copy link

How frequently does the bug occur?

Always

Description

I’m need get data change realtime

use collection.watch() return error [AbortError: Aborted]

use by Realm react-native

this code

const user = useUser()
useEffect(() => {
const setupChangeStream = async () => {
try {
const collection = user!
.mongoClient('mongodb-atlas')
.db('dev')
.collection('Job')

    for await (const change of collection.watch()) {
      // The change event will always represent a newly inserted perennial
      const { documentKey, fullDocument } = change
      console.log(`new document: ${documentKey}`, fullDocument)
    }
  } catch (error) {
    console.error(error)
  }
}

setupChangeStream()

}, [user])

I have set accordingly Examples of every step finished.

https://www.mongodb.com/docs/realm/sdk/react-native/app-services/query-mongodb/#real-time-change-notifications

Thank you.

Stacktrace & log output

[AbortError: Aborted]

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

12.1.0

What services are you using?

Atlas Device Sync

Are you using encryption?

Yes

Platform OS and version(s)

All platform

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@elle-j
Copy link
Contributor

elle-j commented Oct 11, 2023

Hi @BondPiyapan, are you seeing this on both iOS and Android? For Android, the community fetch polyfill that enables text streaming is not working (see their issue here). Can you also verify if you're still experiencing the issue in release mode? (react-native run-android --variant=release)

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Oct 23, 2023
@maichongju
Copy link

I am using expo for my app. There is no --variant=release option, and I still get the Abort error when I use the prod mode. We need to find some workaround for this since this is the only way we can monitor changes from the database.

@elle-j
Copy link
Contributor

elle-j commented Oct 31, 2023

You can always use Device Sync and add listeners to react to changes. Can I ask what the reason is for not using Device Sync for your use case?

@maichongju
Copy link

Good point. I am not sure why I have not tried that feature yet. I will give it a try.

@maichongju
Copy link

After some review and thinking. I think there might be some difficulty for me to use Device Sync. I have a database that many collection and I only want to monitor the notification collection. As what I understand at the moment, Device Sync does not allow sync a single collection. Which means, all other data on the database will also be sync to the device which I don't want and need.

@elle-j
Copy link
Contributor

elle-j commented Nov 3, 2023

Device Sync is very flexible with what should be synced to the device. In your case, to sync only a specific collection, you would only subscribe to that collection. Take e.g. the following example from the docs where only objects of the YourObjectModel is subscribed to (in the initialSubscriptions field):

import React from 'react';
import {AppProvider, UserProvider, RealmProvider} from '@realm/react';

function AppWrapperSync() {
  return (
    <AppProvider id={APP_ID}>
      <UserProvider fallback={LogIn}>
        <RealmProvider
          schema={[YourObjectModel]}
          sync={{
            flexible: true,
            initialSubscriptions: {
              update(subs, realm) {
                subs.add(realm.objects(YourObjectModel));
              },
            },
          }}>
          <RestOfApp />
        </RealmProvider>
      </UserProvider>
    </AppProvider>
  );
}

Since you only have a subscription to YourObjectModel, no other collections will be synced.

If it would help, you can also have a look at one of our example apps and the provided README.

If you encounter what you think is a bug, feel free to open a new issue specifically for that.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants