@@ -72,20 +72,57 @@ class Model {
72
72
) ;
73
73
} ;
74
74
75
- findByAny = ( options , cb ) => {
76
- db . collection ( this . collection )
77
- . find ( options )
78
- . toArray ( ( err , docs ) => {
79
- if ( err ) console . log ( err ) ;
80
- else cb ( docs ) ;
81
- } ) ;
75
+ findByAny = ( options , strict = true , cb ) => {
76
+ let col = db . collection ( this . collection ) ;
77
+ if ( strict ) {
78
+ if ( typeof options == 'object' ) {
79
+ col . find ( options ) . toArray ( ( err , docs ) => {
80
+ if ( err ) console . log ( err ) ;
81
+ else cb ( docs ) ;
82
+ } ) ;
83
+ } else {
84
+ cb ( { error : 'incorrect input given, object expected' } ) ;
85
+ }
86
+ } else {
87
+ if ( Array . isArray ( options ) ) {
88
+ col . find ( {
89
+ $or : options
90
+ } ) . toArray ( ( err , docs ) => {
91
+ if ( err ) console . log ( err ) ;
92
+ else cb ( docs ) ;
93
+ } ) ;
94
+ } else {
95
+ cb ( { error : 'incorrect input given, array expected' } ) ;
96
+ }
97
+ }
82
98
} ;
83
99
84
- findOneByAny = ( options , cb ) => {
85
- db . collection ( this . collection ) . findOne ( options , ( err , result ) => {
86
- if ( err ) console . log ( err ) ;
87
- else cb ( result ) ;
88
- } ) ;
100
+ findOneByAny = ( options , strict = true , cb ) => {
101
+ let col = db . collection ( this . collection ) ;
102
+ if ( strict ) {
103
+ if ( typeof options == 'object' ) {
104
+ col . findOne ( options , ( err , result ) => {
105
+ if ( err ) console . log ( err ) ;
106
+ else cb ( result ) ;
107
+ } ) ;
108
+ } else {
109
+ cb ( { error : 'incorrect input given, object expected' } ) ;
110
+ }
111
+ } else {
112
+ if ( Array . isArray ( options ) ) {
113
+ col . findOne (
114
+ {
115
+ $or : options
116
+ } ,
117
+ ( err , result ) => {
118
+ if ( err ) console . log ( err ) ;
119
+ else cb ( result ) ;
120
+ }
121
+ ) ;
122
+ } else {
123
+ cb ( { error : 'incorrect input given, array expected' } ) ;
124
+ }
125
+ }
89
126
} ;
90
127
91
128
// * =================
0 commit comments