If a saved object does not have `_id` it will be autogenerated.
To identify and update object it should contains `_id` property.
+If callback is not provided this function will be synchronous.
+
Call variations:
save(cname, json object, [cb])
* {Array|Object} jsarr Signle JSON object or array of JSON objects to save
* {Function} `[cb]` Callback args: (error, {Array} of OIDs for saved objects)
+__Return__
+
+ * {Array} of OIDs of saved objects in synchronous mode otherwise returns {this}.
--------------------------------------
### load(cname, oid, cb)
Loads JSON object identified by OID from the collection.
+If callback is not provided this function will be synchronous.
__Arguments__
* {Function} cb Callback args: (error, obj)
`obj`: Retrieved JSON object or NULL if it is not found.
+__Return__
+
+ * JSON object or {null} if it is not found in synchronous mode otherwise return {this}.
+
--------------------------------------
<a name="remove"/>
### remove(cname, oid, cb)
Removes JSON object from the collection.
+If callback is not provided this function will be synchronous.
__Arguments__
NOTE: Only one index can be used in search query operation.
+ NOTE: If callback is not provided this function will be synchronous.
+
QUERY HINTS (specified by `hints` argument):
- $max Maximum number in the result set
- $skip Number of skipped results in the result set
- Cursor#close() Closes cursor and free cursor resources. Cursor cant be used in closed state.
Call variations of find():
- - find(cname, qobj, cb)
- - find(cname, qobj, hints, cb)
- - find(cname, qobj, qobjarr, cb)
- - find(cname, qobj, qobjarr, hints, cb)
+ - find(cname, [cb])
+ - find(cname, qobj, [cb])
+ - find(cname, qobj, hints, [cb])
+ - find(cname, qobj, qobjarr, [cb])
+ - find(cname, qobj, qobjarr, hints, [cb])
__Arguments__
* {Object} `[hints]` JSON object with query hints.
* {Function} cb Callback args: (error, cursor, count)
`cursor`: Cursor object to traverse records
- `count`: Total number of selected records
+ qobj `count`: Total number of selected records
+
+__Return__
+
+ * If callback is provided returns {this}
+ * If no callback and `$onlycount` hint is set returns count {Number}.
+ * If no callback and no `$onlycount` hint returns cursor {Object}.
--------------------------------------------
Call variations of findOne():
- findOne(cname, qobj, cb)
- findOne(cname, qobj, hints, cb)
- findOne(cname, qobj, qobjarr, cb)
- findOne(cname, qobj, qobjarr, hints, cb)
+ findOne(cname, [cb])
+ findOne(cname, qobj, [cb])
+ findOne(cname, qobj, hints, [cb])
+ findOne(cname, qobj, qobjarr, [cb])
+ findOne(cname, qobj, qobjarr, hints, [cb])
__Arguments__
* {Function} cb Callback args: (error, obj)
`obj` Retrieved JSON object or NULL if it is not found.
+__Return__
+
+ * If callback is provided returns {this}
+ * If no callback is provided returns found {Object} or {null}
+
-----------------------------------
<a name="findOne"/>
### update(cname, qobj, orarr, hints, cb)
Call variations of update():
- update(cname, qobj, cb)
- update(cname, qobj, hints, cb)
- update(cname, qobj, qobjarr, cb)
- update(cname, qobj, qobjarr, hints, cb)
+ update(cname, [cb])
+ update(cname, qobj, [cb])
+ update(cname, qobj, hints, [cb])
+ update(cname, qobj, qobjarr, [cb])
+ update(cname, qobj, qobjarr, hints, [cb])
__Arguments__
* {Function} cb Callback args: (error, count)
`count` The number of updated records.
+__Return__
+
+ * If callback is provided returns {this}.
+ * If no callback is provided returns {Number} of updated objects.
+
-----------------------------------
Call variations of count():
- count(cname, qobj, cb)
- count(cname, qobj, hints, cb)
- count(cname, qobj, qobjarr, cb)
- count(cname, qobj, qobjarr, hints, cb)
+ count(cname, [cb])
+ count(cname, qobj, [cb])
+ count(cname, qobj, hints, [cb])
+ count(cname, qobj, qobjarr, [cb])
+ count(cname, qobj, qobjarr, hints, [cb])
__Arguments__
* {Function} cb Callback args: (error, count)
`count`: Number of matching records.
+__Return__
+
+ * If callback is provided returns {this}.
+ * If no callback is provided returns {Number} of matched object.
+
-----------------------------------
<a name="sync"/>
* @param {String} cname Name of collection.
* @param {Array|Object} jsarr Signle JSON object or array of JSON objects to save
* @param {Function} [cb] Callback function with arguments: (error, {Array} of OIDs for saved objects)
- * @return {Array} of OIDs for saved objects in synchronous mode otherwise undefined.
+ * @return {Array} of OIDs of saved objects in synchronous mode otherwise returns {this}.
*/
EJDB.prototype.save = function(cname, jsarr, opts, cb) {
if (!jsarr) {
* @param {String} oid Object identifier (OID)
* @param {Function} [cb] Callback function with arguments: (error, obj)
* `obj`: Retrieved JSON object or NULL if it is not found.
- * @return Retrieved JSON object or NULL if it is not found in synchronous mode otherwise undefined.
+ * @return JSON object or {null} if it is not found in synchronous mode otherwise return {this}.
*/
EJDB.prototype.load = function(cname, oid, cb) {
return this._impl.load(cname, oid, cb);
/*
+ * - (cname, [cb])
* - (cname, qobj, [cb])
* - (cname, qobj, hints, [cb])
* - (cname, qobj, qobjarr, [cb])
if (typeof cname !== "string") {
throw new Error("Collection name 'cname' argument must be specified");
}
- qobj = args[i++];
var next = args[i++];
+ if (typeof next === "function") {
+ cb = next;
+ } else {
+ qobj = next;
+ }
+ next = args[i++];
if (next !== undefined) {
if (next.constructor === Array) {
orarr = next;
if (typeof next === "function") {
cb = next;
}
- } else {
- orarr = hints = cb = null;
}
return [cname, (qobj || {}), (orarr || []), (hints || {}), (cb || null)];
}
* - Cursor#close() Closes cursor and free cursor resources. Cursor cant be used in closed state.
*
* Call variations of find():
+ * - find(cname, [cb])
* - find(cname, qobj, [cb])
* - find(cname, qobj, hints, [cb])
* - find(cname, qobj, qobjarr, [cb])
* @param {Function} [cb] Callback function with arguments: (error, cursor, count) where:
* `cursor`: Cursor object to traverse records
* `count`: Total number of selected records.
- * @return If callback is provided returns undefined.
- * If no callback and $onlycount hint is set returns count number.
- * If no callback and no $onlycount hint returns cursor object.
+ * @return If callback is provided returns {this}.
+ * If no callback and $onlycount hint is set returns count {Number}.
+ * If no callback and no $onlycount hint returns cursor {Object}.
*
*/
EJDB.prototype.find = function() {
* If callback is not provided this function will be synchronous.
*
* Call variations of findOne():
+ * - findOne(cname, [cb])
* - findOne(cname, qobj, [cb])
* - findOne(cname, qobj, hints, [cb])
* - findOne(cname, qobj, qobjarr, [cb])
* @param {Object} [hints] JSON object with query hints.
* @param {Function} [cb] Callback function with arguments: (error, obj) where:
* `obj`: Retrieved JSON object or NULL if it is not found.
- * @return If callback is provided returns undefined.
- * If no callback is provided returns found object or null.
+ * @return If callback is provided returns {this}.
+ * If no callback is provided returns found {Object} or {null}.
*/
EJDB.prototype.findOne = function() {
* @param {Function} [cb] Callback function with arguments: (error, count) where:
* `count`: The number of updated records.
*
- * @return If callback is provided returns undefined.
- * If no callback is provided returns count of updated object.
+ * @return If callback is provided returns {this}.
+ * If no callback is provided returns {Number} of updated objects.
*/
EJDB.prototype.update = function() {
//[cname, qobj, orarr, hints, cb]
* Convenient count(*) operation.
*
* Call variations of count():
+ * - count(cname, [cb])
* - count(cname, qobj, [cb])
* - count(cname, qobj, hints, [cb])
* - count(cname, qobj, qobjarr, [cb])
* @param {Object} [hints] JSON object with query hints.
* @param {Function} [cb] Callback function with arguments: (error, count) where:
* `count`: Number of matching records.
- * @return If callback is provided returns undefined.
- * If no callback is provided returns count of updated object.
+ *
+ * @return If callback is provided returns {this}.
+ * If no callback is provided returns {Number} of matched object.
*/
EJDB.prototype.count = function() {
//[cname, qobj, orarr, hints, cb]