We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
i have this Schema:
var ChatSchema = new Schema({ title: String, founderUser : { type: Schema.ObjectId, ref: 'User'}, members : [{ type: Schema.ObjectId, ref: 'User'}], messages : [{ type: Schema.ObjectId, ref: 'Message'}], }); var MessageSchema = new Schema({ sender: { type: Schema.ObjectId, ref: 'User' }, date: { type: Date, default: Date.now }, text: String, });
now i want to query a chat:
Chat .findOne({ _id:obj._id}) .populate('founderUser', ['username', '_id']) .populate('members', ['username', '_id']) .populate('messages', ['_id'], null, { limit: 10, sort: [['date', 'asc' ]] })
but i also want to populate the messages sender (username & _id) Something like this:
.populate('members.sender', ['username', '_id'])
would be very helpful.
This is my current solution (kinda ugly o_o )
Chat .findOne({ _id: item.obj._id}) .populate('founderUser', ['username', '_id']) .populate('members', ['username', '_id']) .populate('messages', ['_id'], null, { limit: 10, sort: [['date', 'asc' ]] }) .run(function (err, chat) { Message .find({ _id: { $in : chat.messages } }) .populate('sender', ['username', '_id']) .run(function (err, messages) { var jsonObject = chat.toObject(); jsonObject.messages = messages; callback(jsonObject); }) });
i cant use embedded documents for the messages because i cannot filter the messages { limit: 10, sort: [['date', 'asc' ]] }
The text was updated successfully, but these errors were encountered:
closing. tracking this in #601
Sorry, something went wrong.
No branches or pull requests
Hello,
i have this Schema:
now i want to query a chat:
but i also want to populate the messages sender (username & _id)
Something like this:
would be very helpful.
This is my current solution (kinda ugly o_o )
i cant use embedded documents for the messages because i cannot filter the messages { limit: 10, sort: [['date', 'asc' ]] }
The text was updated successfully, but these errors were encountered: