Answer the question
In order to leave comments, you need to log in
How to get data from an array field in mongoose?
There is the following model structure:
var Schema = mongoose.Schema;
var schemaMessage = new Schema({
message: {
type: String,
required: true
},
from: {
type: Schema.ObjectId
},
to: {
type: Schema.ObjectId,
},
date_created: {
type: Date,
default: Date.now
}
});
var schemaTopic = new Schema({
title: {
type: String,
required: true
},
creator: {
type: Schema.ObjectId,
required: true,
ref: 'User'
},
messages: [schemaMessage],
date_created: {
type: Date,
default: Date.now
}
});
schemaTopic.statics.getMessageList = function (topic, callback) {
console.log(topic);
this.aggregate([
{$match: {_id: topic}},
{$unwind: "$messages"}
],callback);
};
Answer the question
In order to leave comments, you need to log in
In general, as it turned out, it was necessary to convert topic to ObjectID {$match: {_id: mongoose.mongo.ObjectID(topic)}}
Changed .htaccess at the root to:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Route::get('/en', '[email protected]_en');
// Должно быть так
Route::get('en', '[email protected]_en');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question