Fetching data from JSONStore collection

improve this page | report issue

Setting up the React Native development environment

Follow the instructions provided in the React Native Gettings Started Page to set up your machine for React Native development.

Adding the JSONStore SDK to your React Native app

The JSONStore SDK for React Native is available as a React Native module from npm.

Getting started with a new React Native project

  1. Create a new React Native project.
     react-native init MyReactApp
    
  2. Add the MobileFirst SDK to your app.
     cd MyReactApp
     npm install react-native-ibm-mobilefirst-jsonstore --save
    
  3. Link all native dependencies to your app.
    react-native link
    

Fetching data from JSONStore collection

Inside your App.js you need to import the following packages:

import { JsonStoreCollection, WLJsonStore } from 'react-native-ibm-mobilefirst-jsonstore';

There are two steps for fetching data from a JSONStore collection:

  1. Opening a Collection, opening a collection allows us to interact with it.
     WLJsonStore.openCollections(['favourites']).then(data => { console.log(data); }).catch(err =>{ console.log(err); });
    
  2. Fetching data from a Collection: After you have opened a collection, you can fetch all the documents using the following API.
     var favCollection = new JSONStoreCollection('favourites');
     favCollection.findAllDocuments()
     .then(data => {
     	console.log("Succesfully fetched all documents from collection!"));
     	console.log("Data: " + JSON.stringify(data));
     .catch(err => {
     	console.log("Error while fetching data from collection. Reason : " + err);
     });
    
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on December 14, 2018