javascript - How to handle multiple fieldnames and values as variables using mongoose "where" method? -


I'm using the where method to pass a field name and value to a Mongoose fineOne Query

  Model.findOne (). Where (field 1, value 1) .where (Field 2, the value 2) .exec (function (fault, callback) {...}  

See the above tasks. However, my the problem is that we have more Area name and values ​​that are passed to the above explanation. I do not know the number of Field and values ​​to be used, because it dynamically to use user Configreshnkman a loop Ways to build clauses where I do not know, but I do not know how. Can anyone help?

a value object as the field that you want to save, and a fields field name to save the array, you can do this:

 < code> var value = {p_last_name: 'Smith', p_first_name: 'John', ...}; var field [ 'p_last_na me', 'p_first_name']; Var query = Model.findOne (); (var i = 0; i & lt; fields.length; ++ i) {var field = field [i]; Query.where (field, value [field]);} Query.exec (call Track);  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -