Find in Bank Mongoose by Nodejs

Asked

Viewed 329 times

2

I’m trying to access the Mongoose bank, 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 no nodejs:

var cepClient = req.body.cep;  
Client.findOne({address:{cep: req.body.cep}} , function(err, cepClient) {...)};  

I want to check if the cep I’m looking for is already registered, if not the variable cepClient will return null. But this way above I can’t access the cep variable inside address that is inside Client. How do I make a Find of a variable within a Array?

1 answer

2

In place of {address:{cep: req.body.cep}}

Tends this way : {address.cep : req.body.cep}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.