const filter = [{
        $match: {
            'fullDocument.username': 'marvel',
            $and: [
                {operationType: 'insert'}
            ]
        }
    }];
    const options = {fullDocument: 'updateLookup'};
    const changeStream = await collection.watch(filter, options);
     changeStream.on('change', next => {
        socket.emit('messages', [next.fullDocument])
    });<?
function save_image($img,$path){
	$curl = curl_init($img);
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_BINARYTRANSFER,1);
	$content = curl_exec($curl);
	curl_close($curl);
	if (file_exists($path)) :
		unlink($path);
	endif;
	$fp = fopen($path,'x');
	fwrite($fp, $content);
	fclose($fp);
}
 
$img = 'http://www.google.com/images/icons/ui/doodle_plus/doodle_plus_google_logo_on_grey.gif';
$path = 'img/logo.gif';
save_image($img, $path);
?><html>
<head>
<script type="text/javascript">
function insertSmile(smile)
{
document.chatform.chatmassage.value += smile;
}
</script>
</head>
<body>
<form method="POST" name="chatform">
<textarea name="chatmassage"></textarea>
</form>
<img src="../chat/smile/smile.gif" alt=";)" onclick="insertSmile(';) ')" />
<img src="https://vk.com/emoji/s/sprite_0.png" alt="%)" onclick="insertSmile('%) ')" />
</body>
</html>