new Store(database, name, reqopt, resopt, internalopt)
Represents a collection store.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
database |
Database | The database instance | ||
name |
string | The collection name | ||
req |
HttpRequest |
<optional> |
null | The http request object |
res |
HttpResponse |
<optional> |
null | The http response object |
internal |
boolean |
<optional> |
true | Whether the store is in internal mode or not |
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The collection name. | ||
database |
Database | The database instance | ||
req |
HttpRequest |
<optional> |
null | The http request object |
res |
HttpResponse |
<optional> |
null | The http response object |
internal |
boolean |
<optional> |
true | Whether the store is in internal mode or not |
Methods
count(options, cb)
Counts data from the collection.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing CountOptionsProcessor as an argument |
cb |
Store~countCallback | The callback function |
Example
store.count(function (x) {
x.query({
firstName: 'John',
lastName: 'Smith'
})
}, function (err, res) {
if(err)
throw err
})
del(options, cb)
Delete data from the collection.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing DelOptionsProcessor as an argument |
cb |
Store~delCallback | The callback function |
Example
store.del(function (x) {
x.query({
firstName: 'John',
lastName: 'Smith'
})
}, function (err, res) {
if(err)
throw err
})
get(options, cb)
Get data from the collection.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing GetOptionsProcessor as an argument |
cb |
Store~getCallback | The callback function |
Example
store.get(function (x) {
x.query()
x.single()
x.cached()
x.fields(['firstName'])
x.options({
limit: 100,
sort: {
firstName: 1
}
})
}, function (err, res) {
if(err)
throw err
})
getCollection(cb)
Get a collection instance for this store.
This collection is coming directly from the mongodb driver, therefore actions will not be filtered by any events injected.
Parameters:
Name | Type | Description |
---|---|---|
cb |
Store~getCollectionCallback | The callback function |
- Tutorials:
Example
store.getCollection(function(err, collection) {
if(err) throw err
collection.find(...)
})
post(options, cb)
Post new data to the collection.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing PostOptionsProcessor as an argument |
cb |
Store~postCallback | The callback function |
Example
store.post(function (x) {
x.data({
firstName: 'John',
lastName: 'Smith'
})
}, function (err, res) {
if(err)
throw err
})
put(options, cb)
Update data in the collection.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing PutOptionsProcessor as an argument |
cb |
Store~putCallback | The callback function |
Example
store.put(function (x) {
x.query({
firstName: 'John',
lastName: 'Smith'
})
x.data({
firstName: 'John2',
lastName: 'Smith2'
})
}, function (err, res) {
if(err)
throw err
})
read(options, cb, next)
Read through a collection invoking the callback for each in the cursor.
Parameters:
Name | Type | Description |
---|---|---|
options |
function | The query options function passing ReadOptionsProcessor as an argument |
cb |
Store~readCallback | The callback function for each result |
next |
Store~readNextCallback | The next function for all results upon complete |
Example
store.read(function (x) {
x.query()
x.fields(['firstName'])
x.options({
limit: 100
})
}, function (err, res) {
if(err)
throw err
}, function() {
console.log('completed!')
})
Type Definitions
countCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The count result |
delCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The delete results |
getCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The results |
getCollectionCallback(err, collection)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
collection |
string | The mongodb driver collection instance |
postCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The posted results |
putCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The update results |
readCallback(err, res)
Parameters:
Name | Type | Description |
---|---|---|
err |
Exception | The exception object |
res |
object | The cursored result |