Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何按日期分组和显示聊天信息_Node.js_Mongodb_Angular_Mongoose - Fatal编程技术网

Node.js 如何按日期分组和显示聊天信息

Node.js 如何按日期分组和显示聊天信息,node.js,mongodb,angular,mongoose,Node.js,Mongodb,Angular,Mongoose,我正在使用Nodejs、MongoDB(Mongoose)和angular5创建聊天应用程序。我想知道如何按日期分割聊天信息。所以我可以显示哪些消息是在哪一天发送的,比如whatsapp是如何发送的 MongoDB-模式。 let MessageSchema = new Schema({ chat_id: { type: Schema.Types.ObjectId, ref: 'Chat', required: true,

我正在使用Nodejs、MongoDB(Mongoose)和angular5创建聊天应用程序。我想知道如何按日期分割聊天信息。所以我可以显示哪些消息是在哪一天发送的,比如whatsapp是如何发送的

MongoDB-模式。

let MessageSchema = new Schema({

        chat_id: {
            type: Schema.Types.ObjectId, ref: 'Chat',
            required: true,
        },
        body: {
            type: String,
            required: true,
        },
        author: {
            type: Schema.Types.ObjectId, ref: 'User',
            required: true,
        },
        isRead: Boolean,
    },
    {
        timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
    });
NodeJs-API函数/chat/:获取整个对话的id

show(req, res) {

        let id = req.params.id;

        Chat.findOne({_id: id})
            .populate('participants')
            .populate({
                path: 'messages',
                populate: {path: 'author'},
            })
            .exec((err, chat) => {

                if (err) {
                    return res.status(404).json({

                        success: false,
                        status: 400,
                        data: err,
                        message: 'Error retrieving user conversations',
                    });
                }

                return res.status(200).json({

                    success: true,
                    status: 200,
                    data: chat,
                    message: 'Successfully retrieve conversation',

                });

            });

    }
角度-chat.component.ts

   getConversation() {

        this.route.params.switchMap((params) => {
            let conversation_id = params['id'];
            return this.conversationService.get(conversation_id);
        }).subscribe((res) => {
            this.conversation = res.data;
            this.getMessages(this.conversation._id); // Socket call
        });
    }


<ng-template ngFor let-message [ngForOf]="conversation?.messages" let-i="index">
getConversation(){
this.route.params.switchMap((params)=>{
让对话_id=params['id'];
返回此.conversationService.get(会话id);
}).订阅((res)=>{
this.conversation=res.data;
this.getMessages(this.conversation.\u id);//套接字调用
});
}