API Docs for:
Show:

Factory Class

Defined in: index.js:4

Constructor

Factory

(
  • [model]
  • factory
)

Defined in index.js:4

Parameters:

  • [model] Object optional

    The mongoose.model('name') or nothing if you want a plain factory Object

  • factory Function

    The factory Object

    • object Object

      The return Object of function, if you want you can include another factory in the obj/child. please look at the test/index.js ile in the repo how it is included

      • [key] String | Number | Array optional
        value
      • [$child] Object optional
        you can nest children in other children as you wish. you can use empty children, too
      • [$child.child_name] Object | Function optional

Example:

new Factory(mongoose.model('name'), function() { return obj; });

Methods

_compareObjSync

(
  • mObj
  • obj
)
Object private

Defined in index.js:59

checks if new mongoose.model(object) got a wrong field value

Parameters:

  • mObj Object

    mongoose Object

  • obj Object

    plain Object

Returns:

Object:

if no error then false else new Error

_getFactory

(
  • options
  • callback
)
Function private async

Defined in index.js:139

get factory object

Parameters:

  • options Object

    options field

  • callback Function

    callback

Returns:

Function:

callback(err, factoryObject)

_getNewDocs

(
  • options
  • callback
)
Function private async

Defined in index.js:104

handles the options field from build

Parameters:

  • options Object

    options field

  • callback Function

    callback

Returns:

Function:

callback(err, docs)

_mergeObjsSync

(
  • obj1
  • obj2
)
Object private

Defined in index.js:82

merges obj2 into obj1

Parameters:

  • obj1 Object

    Object

  • obj2 Object

    Object

Returns:

Object:

merged object

_newDoc

(
  • [options]
  • callback
)
Object private

Defined in index.js:173

set new doc

Parameters:

  • [options] Object optional

    {Object} options field

  • callback Function

    callback

Returns:

Object:

mongoose factory ? mongoose Object : plain Object

build

(
  • [options]
  • callback
)
async

Defined in index.js:30

builds a mongoose Object or a plain Object

Parameters:

  • [options] Object optional

    {Object} options field, if nothing specified then return one default doc

    • [$factory="default"] String optional

      write the child factories down seperated by space which you want to build. $child{first: {$child: second{}}} would be options.$factory = "first second"

    • [$seq=this.sequenc] Number optional

      when provided resets sequence with given num

    • [$doc] optional

      {Object} Set the value of the doc to create

      • [$factory=options.$factory] String optional
        same as options.$factory
      • [$num=1] Number optional
        set number of docs which should be created
      • [key] String | Number | Array optional
        value which should be merged with parent factory and this factory
    • [$docs=[] optional

      {Array} if you want to build multiple different docs, basically the same as options.$doc in an Array -> [ options.$doc, options.$doc ]

  • callback Function

    callback

count

()

Defined in index.js:259

instead of factory.model.count see http://mongoosejs.com/docs/api.html#model_Model.count

create

(
  • [options]
  • [callback]
)
Function async

Defined in index.js:211

accepts options as factory.build

Parameters:

  • [options] Object optional

    {Object} options field

  • [callback] Function optional

    callback

Returns:

Function:

with (err, docs)

Example:

//with mocha you can pass done() as a callback factory.create({$doc: {$num: 3}}, done()); factory.create(function(err, docs){ //insert here whatever you want });

find

()

Defined in index.js:246

instead of factory.model.find see http://mongoosejs.com/docs/api.html#model_Model.find

findOne

()

Defined in index.js:272

instead of factory.model.findOne see http://mongoosejs.com/docs/api.html#model_Model.findOne

remove

(
  • [options]
  • [callback]
)
Function async

Defined in index.js:285

removes docs which matches options from factory.model

Parameters:

  • [options] Object optional

    options field as in mongoose.model.remove

  • [callback] Function optional

    callback

Returns:

Function:

returns the same callback as http://mongoosejs.com/docs/api.html#model_Model.remove

stringMethods

(
  • doc
)
Object private

Defined in index.js:191

applies strMethods.all() to each value of object

Parameters:

  • doc Object

    takes a document

Returns:

Object:

object with applied strgMethods