Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
SDK de Dispositivo Atlas

Quick Start - Web SDK

Esta página muestra cómo conectar el SDK web de Realm a un backend de Atlas App Services, autenticar a un usuario y trabajar con datos. Antes de comenzar, necesitará... Crea una aplicación para que la use tu aplicación web.

npm install realm-web
yarn add realm-web

Agregar un <script> etiqueta al <head> de tu archivo HTML para cargar el Realm Web SDK como una variable global desde una red de distribución de contenido.

Utilice la versión más reciente:

<script src="https://unpkg.com/realm-web/dist/bundle.iife.js"></script>

O importar una versión específica:

<script src="https://unpkg.com/realm-web@1.5.1/dist/bundle.iife.js"></script>

Near the top of any JavaScript or TypeScript file that uses Realm, add the following import statement:

import * as Realm from "realm-web";

Nota

If you loaded the SDK using a <script> tag then you don't need to import the SDK to use it. Instead, you can access it using the global Realm variable.

To use App Services features such as authentication and sync, access your App Services App using your App ID. You can find your App ID in the App Services UI.

// Add your App ID
const app = new Realm.App({ id: APP_ID });

Cuando la autenticación anónima está habilitada, los usuarios pueden iniciar sesión en su aplicación sin proporcionar ninguna información de identificación:

// Create an anonymous credential
const credentials = Realm.Credentials.anonymous();
// Authenticate the user
const user = await app.logIn(credentials);
// `App.currentUser` updates to match the logged in user
console.assert(user.id === app.currentUser.id);

Servicios de aplicación ofrece muchas formas adicionales de autenticar, registrar y vincular usuarios.

Tip

To call a function, use the Realm.User.functions interface to call your serverless functions as if they were regular JavaScript functions defined on the object.

const summed = await user.functions.sum(2, 3);
console.assert(summed === 5);

Next

Bienvenido a la Docs de Atlas Device SDK

En esta página