here is my models:
var RaceSchema = new mongoose.Schema({
name: {
type: String
},
owner:{
type: mongoose.Schema.ObjectId, ref:"user"
}
});
var UserSchema = new mongoose.Schema({
username: {
type: String
}
});
Here is an example of my collections:
//Races
{
"_id": {
"$oid": "5b5740c54befec2594ce4cb0"
},
"name": "Race1"
"owner": {
"$oid": "5b34f870e1eef640f8cb43e4"
}
}
//User
{
"_id": {
"$oid": "5b34f870e1eef640f8cb43e4"
},
"username":"admin"
}
I want to find races whose owner matchs with field username. I mean: "I want to find races whose owner is admin"
I'm trying this with:
Race.find().populate('users', {username: 'admin'}).exec(function (err, races) {
....
}
But always the result is the same, the search gives me all races.
EDIT 1
SQL Sentence would be:
Select * FROM Races,Users WHERE owner=user._id AND user.username='admin'
Or something like that