I'm trying to access the mongoose database by doing a find on the nodejs. In mongoose, I have the following data:
Client:{
name: {type: String, trim: true, required: false, default: ""},
address:{
country: {type: String, trim: true, required: false, default: ""},
cep : {type: String, trim: true, required: false, default: ""},
state: {type: String, trim: true, required: false, default: ""},
city: {type: String, trim: true, required: false, default: ""},
neighborhood: {type: String, trim: true, required: false, default: ""},
street: {type: String, trim: true, required: false, default: ""},
number: {type: Number, required: false, default: 0},
complement: {type: String, trim: true, required: false, default: ""}
},
}
And I do the following find on nodejs:
var cepClient = req.body.cep;
Client.findOne({address:{cep: req.body.cep}} , function(err, cepClient) {...)};
I want to check if the zip I'm looking for is already registered, otherwise the variable cepClient will return null.
However in this way I can not access the variable cep within address that is inside Client. How do I make a Find
of a variable within a Array
?