Factory Class
Constructor
Factory
-
[model]
-
factory
Parameters:
-
[model]
Object optionalThe mongoose.model('name') or nothing if you want a plain factory Object
-
factory
FunctionThe factory Object
-
object
ObjectThe 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 optionalvalue -
[$child]
Object optionalyou 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; });
Item Index
Methods
_compareObjSync
-
mObj
-
obj
checks if new mongoose.model(object) got a wrong field value
Parameters:
-
mObj
Objectmongoose Object
-
obj
Objectplain Object
Returns:
if no error then false else new Error
_getFactory
-
options
-
callback
get factory object
Parameters:
-
options
Objectoptions field
-
callback
Functioncallback
Returns:
callback(err, factoryObject)
_getNewDocs
-
options
-
callback
handles the options field from build
Parameters:
-
options
Objectoptions field
-
callback
Functioncallback
Returns:
callback(err, docs)
_mergeObjsSync
-
obj1
-
obj2
merges obj2 into obj1
Parameters:
-
obj1
ObjectObject
-
obj2
ObjectObject
Returns:
merged object
_newDoc
-
[options]
-
callback
set new doc
Parameters:
-
[options]
Object optional{Object} options field
-
callback
Functioncallback
Returns:
mongoose factory ? mongoose Object : plain Object
build
-
[options]
-
callback
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 optionalwrite 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 optionalwhen provided resets sequence with given num
-
[$doc]
optional{Object} Set the value of the doc to create
-
[$factory=options.$factory]
String optionalsame as options.$factory -
[$num=1]
Number optionalset number of docs which should be created -
[key]
String | Number | Array optionalvalue 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
Functioncallback
create
-
[options]
-
[callback]
accepts options as factory.build
Parameters:
-
[options]
Object optional{Object} options field
-
[callback]
Function optionalcallback
Returns:
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 });
findOne
()
instead of factory.model.findOne see http://mongoosejs.com/docs/api.html#model_Model.findOne
remove
-
[options]
-
[callback]
removes docs which matches options from factory.model
Parameters:
-
[options]
Object optionaloptions field as in mongoose.model.remove
-
[callback]
Function optionalcallback
Returns:
returns the same callback as http://mongoosejs.com/docs/api.html#model_Model.remove
stringMethods
-
doc
applies strMethods.all() to each value of object
Parameters:
-
doc
Objecttakes a document
Returns:
object with applied strgMethods