• 1.7.1. Data Operation

        • x.Get

          ECBOOK.prototype.Get( ids [, options ], function( res, err ) { ... })

          ids : string || array of string
          options : object (see below : optional)
          res : object || array of object (the order of res is same as ids order)
          err : Error (in case)
          return value : self (= this)

          options : acceptable keys

          • fields : array of the fields to get
            (e.g. {fields: ["name","type",...]} )
          • hashWrite : write to internal hash (default:true)
            (e.g. {hashWrite:false})
          • withdeleted : avoid auto set of delete flag ({_flg:{$ne:0}})
            (e.g. {withdeleted:true } ... data with delete flag is also received )

          Gets document(s) by the system key(=_id) or a primary key ( an item in structure defined as 'pkey' ).
          If ids don't exist in the client hash, Get() tries to get them from database automatically.

          x.Get("abcdefgh", function(res) { res && alert(JSON.stringify(res)); });
          var a = ["abcdefgh","ijklmnop"];
          x.Get(a, {fields:["name","type"], hashWrite:false}, function(res, err) { err && (throw err);
          res.forEach(function(t){ ... });
          });
          // Here x is ECBOOK instance.

          notes : When setting null or 3em>undefined at param ids, synquery throws Error and callback function is not called.

        • x.Put

          ECBOOK.prototype.Put( docs [, function( res , err ) { ... }])

          docs : object || array of object
          res : array of object , err : Error (in case)
          return value : self (= this)

          Puts document(s) docs to database.
          Normally, if the same _id exists in database then update, otherwise insert.
          Here system parameters (_last, _hist_) are automatically set to docs.

          x.Put(obj, function(res, err) { err && (Throw err); });
          x.Put(objs, function(res) { res && res.forEach(function(t) { ... }); });
          // Here x is ECBOOK instance.
        • x.Del

          ECBOOK.prototype.Del( id [, function( res , err ) { ... }])

          id : string
          res : array of object , err : Error (in case)
          return value : self (= this)

          Deletes an document from the client hash, and marks the document on database as "deleted"
          [logical delete (= _flg is set to 0)],
          by using system key(=_id) or a primary key ( an item in structure defined as 'pkey').

          The document cannot be get without using "withdeleted" option. (see Find, Count)
          Callback function is invoked with deleted object.

          notes : "delete" with multiple ids is not supported.

        • x.Remove

          ECBOOK.prototype.Remove( id [, function( res , err ) { ... }])

          id : string
          res : array of object , err : Error (in case)
          return value : self (= this)

          Delete an document from the client hash and database,
          by using system key(=_id) or primary key ( an item in structure defined as 'pkey'). [physical delete]
          The document cannot be get any more.
          Callback function is invoked with removed object.

          notes : "delete" with multiple ids is not supported.

          notes : The Remove() function is changed not to remove data record completely.
          Document contents except system keys (_id, _hist_, _last and _flg) are deleted.
          And _flg is set to 0. (same as Del()).

        • x.Count

          ECBOOK.prototype.Count([ selector ,] function( res , err ) { ... });

          selector : object (see below)
          res : number , err : Error (in case)
          return value : self (= this)

          Count() counts number of documents in a book by using selector. The API always accesses to the server.

          selector : capable to use mongodb selectors.

          • $ function and regular expression are also accepted.
          • If you set "filter" in BOOK, filter is automatically set as selector.
          • If you want to use regular expression, quot the regular expression(e.g. {name:'/hoge/'}).
          • For more information => see mongodb querying
        • x.Find

          ECBOOK.prototype.Find([ selector ,] [ options ,] function( res , err ) { ... });

          selector : object (see below) , options : object (see below)
          res : array of strings(ids) , err : Error (in case)
          return value : self (= this)

          Gets system keys (=_id) by using selector and options. The API always accesses to the server.

          selector : capable to use mongodb selectors.

          • $ function and regular expression are also accepted.
          • If you set "filter" in BOOK, filter is automatically set as selector.
          • If you want to use regular expression, quot the regular expression(e.g. {name:'/hoge/'}).
          • For more information => see mongodb querying

          options : acceptable keys

          • sort : Sorts with the keys added. 1 is asc (up) and -1 is desc (down) sort mode
            (e.g. {sort: {name:1, type: -1 }} ... sort by 1:name(asc mode), 2:type(desc mode))
          • limit : Limits the count of keys returned
            (e.g. {limit: 50} ... return top 50 of the selected keys)
          • skip : Skips the keys from top.
            (e.g. {limit: 50, skip: 20} ... return from 21st to 70th of the selected keys)
          • withdeleted : avoid auto set of delete flag ({_flg:{$ne:0}})
            (e.g. {withdeleted:true } ... data with delete flag is also received )
          var basket = { // Definition of the BOOK structure
          title: 'BASKET', table: "BASKET",
          structure: [
          ["id", "id", "integer", "", {pkey:true}, 10],
          ["name", "name", "string", "", {}, 30],
          ["type","type","select",{ 'fruit':1, 'vegetable':2, 'meat':3, 'chilled':4 },{},15],
          ["value", "value per one", "account", "", {}, 45]
          ]
          };
          var self = top.BOOK(basket);
          self.Find({type:1 /*fruit*/}, { sort: {value:1}, limit: 100 }, findCallback);
          function findCallback(keys, err) { err && onerror(err);
          alert('type fruit keys are:' + keys.toString());
          }
          function onerror(err) { throw err; }

          notes : You cannot set only options.
          If you want to set options without selector, use " self.Find({}, options, callback) "

        • x.Remove

          ECBOOK.prototype.Read( selector , filter, function( res , err ) { ... })

          selector : object (see below) , filter : string / array / object
          res : array of strings(ids) , err : Error (in case)
          return value : self (= this)

          Gets parts of records.

          self.Read({}, "aa bb", function(res) { ... }); // reads in array/array
          self.Read({}, ["aa","bb"], function(res) { ... }); // reads in object of array
          self.Read({}, {"aa":"aa","bb":"bb"}, function(res) { ... }); // reads in array of object
        • x.MapReduce

          ECBOOK.prototype.MapReduce( map , reduce , [ options ,] function( res , err ) { ... })

          map : function (map function for mongodb)
          reduce : function (reduce function for mongodb)
          options : object (see below)
          res : array ( result of map-reduce), err : Error (in case)

          Execute MapReduce on server database.

          options : acceptable keys

          • finalize : function (finalize function for map-reduce)
        • x.createIndex

          ECBOOK.prototype.createIndex( )

          reIndex by the structure you defined.
          Note that your own index (manually ensured) is NOT kept. All index of the collection will be changed over.

        • x.DropCollection

          ECBOOK.prototype.DropCollection(function( res , err ) { ... })

          res : undefined, err : Error (in case)

          Drops the database collection.

          notes : There is no way to recover the database.
          Please use this function carefully with considering your risk.