Class: Lens.DB

Lens.DB provides MongoDB-like database that can easily be synchronized between different Lens applications or LuXoR devices.

Databases are reactive, and can be used in conjunction with Lens.autorun. See Reactivity for more on reactive programming in Lens.

Lens.DB is taken from Meteor. Once you've created a collection using Lens.DB#Collection, you can use the Meteor Collection API to query the collection and insert new records.

See Databases for more information on the types of databases available.

Static Methods

Lens.DB._connect() ARCore/db.js, line 441

Connects to a database on another machine.

Lens.DB.app(name) → {Lens.DB} ARCore/db.js, line 302

Returns a new persistent database accessible only to this app.

Argument Type Description
name String

Lens.DB.inMemory() → {Lens.DB} ARCore/db.js, line 293

Returns a new in-memory database.

Lens.DB.machine(name) → {Lens.DB} ARCore/db.js, line 313

Returns a new persistent database accessible only to this app.

Argument Type Description
name String

Lens.DB.published(name) → {Lens.DB} ARCore/db.js, line 325

Returns a new database that is published to nearby LuXoR devices. You can find nearby published databases using Lens.Machines

Argument Type Description
name String

Lens.DB.server(url, isLensDBServer) → {Lens.DB} ARCore/db.js, line 346

Returns a new database that is connection to an external Meteor backend.

Argument Type Attributes Description
url String

The URL of the Meteor app.

isLensDBServer Boolean <optional>

Set this to true if the Meteor app is a LuXoR DB server (which allows LuXoR to create Collection client- side). Defaults to false.

Lens.DB.shared(name, callback) ARCore/db.js, line 367

Returns a new ad-hoc shared database. A shared database is only persisted for as long as the machine that created it is connected. Moreover, unlike a published database, you need not have one machine publish the database and other connect to it. Rather, have all machines call DB.shared and Lens with automatically select a "master" and have the other machines connect to it.

Argument Type Description
name String
callback function

Callback to invoke with the shared Lens.DB once one has been created.

Instance Properties

name: String

The name of this database. Read-only.

machine: String

The machine who's backend is managing this DB. Null for server and in-memory databases. Read-only.

Instance Methods

close() ARCore/db.js, line 251

Closes the connection to the database backend. You can still use collections, but they won't be synced with the server, and other clients of published or shared databases won't see you as a peer.

Collection(collectionName, onReady) → {Collection} ARCore/db.js, line 215

Returns a new database collection. See the Meteor Collection API for documentation on how to make queries against the collection.

Automatically calls open if this database isn't open.

Argument Type Attributes Description
collectionName String

Name of the collection. If this name already exists, returns the existing collection.

onReady function <optional>

You can use the returned collection immediately, but it won't have synced with the server immediately. If you pass this function, it will be called when the collection finished its initial sync with the server.

connection() ARCore/db.js, line 231

Returns the Meteor connection to this DB's server. This object is the same as the one returned by DDP.connect.

Returns null for in-memory databases.

Automatically calls open if the database isn't open.

open() ARCore/db.js, line 242

Opens the connection to the database backend. This is automatically called by Collection and connection; you only need to call this if you have called close and want to re-open the connection

peers() ARCore/db.js, line 276

Returns an array of Machines that are also connected to this database. A reactive data source.