QnaList > Groups > Mongodb-User > Apr 2016
faq

[mongodb-user] I Want To Populate OR Search... Plz Help Me

first, I can't speak English well.. Understanding me
I have this model
var user = mongoose.Schema({
email: ....
password: .....
name : ...
company : ...
position : ....
phoneNumber : ...
signDate : Date,
friends: [{ type : mongoose.Schema.Types.ObjectId ,unique: true, ref: 
'user' }],
accessToken: .....
}); 
and 
var friend = mongoose.Schema({
friends: [{ type : mongoose.Schema.Types.ObjectId ,unique: true, ref: 
'user' }]
});
Using these two, I want to search all the fields using a single keyword.
        var fds = new Friend;
User.findOne({email : user.email})
.populate({ 
 path : 'friends',
 match     : ''''empty''''
})
.exec(function (err, fd) {
 if(!err){
  fds = fd.friends;
  res.render('account/friend', { layout: false, user: user, friends: fds });
 }else{ console.log(err)}
});
I don't know what to put in that empty space...
var term = new RegExp(req.body.inputAll, 'i');
User.find().or([{ email: { $regex: term }}, 
               { name: { $regex: term }}, 
               { company: { $regex: term }}, 
               { position: { $regex: term }}, 
               { phoneNumber: { $regex: term }}])
Elsewhere this was the word OR search. But I don't know populate OR search.
or other way besides to using the Match?
please, help me...
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/45decd46-a1a4-45e2-8200-cf42fd5600b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

asked Apr 4 2016 at 03:30

Kim Taesik 's gravatar image



Related discussions

Tagged

Group Mongodb-user

asked Apr 4 2016 at 03:30

active Apr 4 2016 at 03:30

posts:1

users:1

©2013 QnaList.com