== How to fix it in Mongoose

=== Code examples

include::../../common/fix/code-rationale.adoc[]

==== Noncompliant code example

[source,javascript,diff-id=1,diff-type=noncompliant]
----
const mongoose = require('mongoose');

function(req, res) {
    let query = { user: req.query.user, city: req.query.city };
    const userModel = mongoose.model('User', userSchema);
    userModel.find(query, (err, users) => {}); // Noncompliant
}
----

==== Compliant solution

[source,javascript,diff-id=1,diff-type=compliant]
----
const mongoose = require('mongoose');

function (req, res) {
    let query = { user: req.query.user.toString(), city: req.query.city.toString() };
    const userModel = mongoose.model('User', userSchema);
    userModel.find(query, (err, users) => {});
}
----

=== How does this work?

include::../../common/fix/plain-string-values.adoc[]

=== Pitfalls

include::../../common/pitfalls/code-execution.adoc[]
