Closed molerat619 closed 9 years ago
@molerat619 please share your full schema in here for the models
var GroupSchema = new Schema({
name: {type: String, unique: true, required: true, uppercase: true},
...
program: {type: Schema.ObjectId, ref: 'Program'},
departure_country: {type: Schema.ObjectId, ref: 'Country'},
destination_country: {type: Schema.ObjectId, ref: 'Country'},
airline: {type: Schema.ObjectId, ref: 'Airline'},
...
});
var CountrySchema = new Schema({
name: {type: String, required: true, unique: true, uppercase: true},
code: {type: String, required: true, unique: true, uppercase: true},
...
})
I got it working now, but I ask myself, if somehow I can do Group.paginate({destination_country.name: "Germany"})
or so. That would be more interesting.
Please feel free to drop a gist or a repo/files/anything so that I can understand your issue better. Thanks!
Could you please give us the solution i am stuck at similar place to sort/search in referenced objects
Please give a schema.
This is my user schema var userSchema = mongoose.Schema({id:{type:String,index:true},group:{type: mongoose.Schema.Types.ObjectId, ref: 'group' ,default:null}}).plugin(mongoosePaginate);
this is my group schema var groupSchema =mongoose.Schema({name:{type:String,index:true},parentGroupId:mongoose.Schema.Types.ObjectId},{id:false,toJSON:{virtuals:true}}).plugin(mongoosePaginate);
for pagination of user i am using below code in which sort param is like {id:-1}
db.user.paginate(f,{page:pageNo,limit:count,columns:db.sim.projection,populate:[db.user.groupPopulation],sortBy:sortParam})
I want to sort user using group.name in the paginate
or even search which looke like
f["$text"] = { $search :searchQ};
is not searching in populated froupname
Hi,
when I do the following:
Group.paginate({destination_country: "some-country-id-1234"}) ...
I get no results back, even though there should be some. Using
{}
as query gives me all Groups, so the rest of the paginate-function is okay.Group is a model with destination_country as a reference to the Country Model (which also works fine with all my other needs).