Giter VIP home page Giter VIP logo

loopback-example-mongodb's Introduction

#loopback-example-mongodb

Basic instructions:

git clone https://github.com/strongloop/loopback-example-mongodb.git
cd loopback-example-mongodb
npm install

Then run any script in server/bin (for example, node server/bin/discover-schema.js).

##Prerequisites

###Tutorials

###Knowledge

##Procedure

###1. Create the application

####Application information

  • Name: loopback-example-mongodb
  • Directory to contain the project: loopback-example-mongodb
slc loopback loopback-example-mongodb
... # follow the prompts
cd loopback-example-mongodb

###2. Install the connector

npm install --save loopback-connector-mongodb

###3. Configure the datasource

####Datasource information

  • Datasource: accountDs
  • Connector: MongoDB
slc loopback:datasource accountDs
... # follow the prompts

Add the datasource configurations to server/datasources.json.

We provide a demo server for convenience sake, but feel free to use your own database server.

###4. Add a model

####Model information

  • Name: Account
    • Datasource: accountDs
    • Base class: PersistedModel
    • Expose via REST: Yes
    • Custom plural form: Leave blank
    • Properties
      • email
        • String
        • Not required
      • createdAt
        • Date
        • Not required
      • lastModifiedAt
        • Date
        • Not required
slc loopback:model Account
... # follow the prompts

###5. Add a script to migrate data

Create a directory for to store scripts.

mkdir server/bin

bin is a directory name commonly used for executable files on unix and unix-like systems.

Create automigrate.js inside the bin directory.

datasSource.automigrate() requires INSERT object, CREATE DDL, and DROP DDL rights to execute properly.

####Test the script

#####WARNING dataSource.automigrate() creates a new table in the database if it doesn't exist. If the table already exists, it will be DESTROYED and ALL existing data will be dropped. If you want to keep the existing data, use datasource.autoupdate() instead.

node server/bin/automigrate.js

This script creates two models in the specified data source.

You can view the newly inserted data using built-in API explorer. Start the application with slc run and browse to localhost:3000/explorer to inspect the data.

###6. Add a script to perform instance introspection

Discovery is the process of reverse engineering a LoopBack model from an existing database schema.

The LoopBack MongoDB connector does not support discovery. However, you can use [instance instrospection], which creates LoopBack model from an existing JavaScript object.

See the instance introspection documentation for more information.

###8. Conclusion

You've successfully implemented various MongoDB database features provided by LoopBack. See the official documentation and loopback-connector-mongodb for more information.


loopback-example-mongodb's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.