new MongoDBAdapter(opts)
MongoDBAdapter class.
Parameters:
Name | Type | Argument | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
<optional> |
Configuration opts. Properties
|
Example
import {DS} from 'js-data' import MongoDBAdapter from 'js-data-mongodb' const store = new DS() const adapter = new MongoDBAdapter({ uri: 'mongodb://localhost:27017' }) store.registerAdapter('mongodb', adapter, { 'default': true })
Members
-
client :Object
-
A Promise that resolves to a reference to the MongoDB client being used by this adapter.
Type:
- Object
Methods
-
create(Resource, props, opts)
-
Create a new record.
Parameters:
Name Type Argument Description Resource
Object The Resource.
props
Object The record to be created.
opts
Object <optional>
Configuration options.
Returns:
- Type
- Promise
-
destroy(Resource, id, opts)
-
Destroy the record with the given primary key.
Parameters:
Name Type Argument Description Resource
Object The Resource.
id
string | number Primary key of the record to destroy.
opts
Object <optional>
Configuration options.
Returns:
- Type
- Promise
-
destroyAll(Resource, query, opts)
-
Destroy the records that match the selection query.
Parameters:
Name Type Argument Description Resource
Object the Resource.
query
Object <optional>
Selection query.
opts
Object <optional>
Configuration options.
Returns:
- Type
- Promise
-
find(Resource, id, opts)
-
Retrieve the record with the given primary key.
Parameters:
Name Type Argument Description Resource
Object The Resource.
id
string | number Primary key of the record to retrieve.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description with
Array.<string> <optional>
[] TODO
Returns:
- Type
- Promise
-
findAll(Resource, query, opts)
-
Retrieve the records that match the selection query.
Parameters:
Name Type Argument Description Resource
Object The Resource.
query
Object Selection query.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description with
Array.<string> <optional>
[] TODO
Returns:
- Type
- Promise
-
getClient()
-
Return a Promise that resolves to a reference to the MongoDB client being used by this adapter.
Useful when you need to do anything custom with the MongoDB client library.
Returns:
MongoDB client.
- Type
- Object
-
getQuery()
-
Map filtering params in a selection query to MongoDB a filtering object.
Handles the following:
- where
- and bunch of filtering operators
Returns:
- Type
- Object
- where
-
getQueryOptions()
-
Map non-filtering params in a selection query to MongoDB query options.
Handles the following:
- limit
- skip/offset
- orderBy/sort
Returns:
- Type
- Object
-
loadBelongsTo()
-
TODO
Returns:
- Type
- Promise
-
loadHasMany()
-
TODO
Returns:
- Type
- Promise
-
loadHasOne()
-
TODO
Returns:
- Type
- Promise
-
makeBelongsToForeignKey()
-
TODO
Returns:
- Type
- *
-
makeHasManyForeignKey()
-
TODO
If the foreignKeys in your database are saved as ObjectIDs, then override this method and change it to something like:
return this.toObjectID(Resource, this.constructor.prototype.makeHasManyForeignKey.call(this, Resource, def, record))
There may be other reasons why you may want to override this method, like when the id of the parent doesn't exactly match up to the key on the child.
Returns:
- Type
- *
-
makeHasManyForeignKey()
-
TODO
Returns:
- Type
- *
-
origify()
-
TODO
Returns:
- Type
- Object
-
translateId()
-
TODO
Returns:
- Type
- *
-
update(Resource, id, props, opts)
-
Apply the given update to the record with the specified primary key.
Parameters:
Name Type Argument Description Resource
Object The Resource.
id
string | number The primary key of the record to be updated.
props
Object The update to apply to the record.
opts
Object <optional>
Configuration options.
Returns:
- Type
- Promise
-
updateAll(Resource, props, query, opts)
-
Apply the given update to all records that match the selection query.
Parameters:
Name Type Argument Description Resource
Object The Resource.
props
Object The update to apply to the selected records.
query
Object <optional>
Selection query.
opts
Object <optional>
Configuration options.
Returns:
- Type
- Promise