小编Jat*_*t90的帖子

使用 Axios (Node JS) 的 HTTP 流

我正在尝试通过 HTTP 传输价格数据(不知道他们为什么不使用 websockets..)并且我使用 axios 发出正常的 REST API 请求,但我不知道如何处理“传输编码”:'分块”类型的请求。

此代码只是挂起并且不会产生任何错误,因此假设它正在工作但无法处理响应:

const { data } = await axios.get(`https://stream.example.com`, {headers: 
{Authorization: `Bearer ${token}`, 'Content-Type': 'application/octet- 
stream'}})

console.log(data) // execution hangs before reaching here
Run Code Online (Sandbox Code Playgroud)

感谢你的帮助。

工作解决方案:正如下面的答案所指出的,我们需要添加一个responseType:流作为axios选项,并在响应上添加一个事件监听器。

工作代码:

const response = await axios.get(`https://stream.example.com`, {
  headers: {Authorization: `Bearer ${token}`}, 
  responseType: 'stream'
});

const stream = response.data
stream.on('data', data => { 
  data = data.toString()
  console.log(data) 
})
Run Code Online (Sandbox Code Playgroud)

javascript http node.js axios

19
推荐指数
1
解决办法
7万
查看次数

从本地迁移到 MongoDb Atlas

我正在尝试将本地 MongoDB 迁移到 Atlas。

我设法使用 localhost 运行 mongodump 命令,并且可以看到 ./dump/data.bson 中的文件

但是,当我现在想要将此转储恢复到 Atlas 时,我收到“失败:连接到数据库服务器时出错:没有可访问的服务器”。

这很奇怪,因为我可以使用以下命令从 mongo shell (v4.0) 连接到 Atlas:“mongo mongodb+srv://cluster0-xxxxxx.mongodb.net/test --username Bob”,其中提示我输入密码并连接良好。

这是 mongorestore 命令,它给了我上述连接错误:

mongorestore --ssl --host mongodb+srv://cluster0-xxxxx.mongodb.net/test --username Bob --authenticationDatabase admin --dir dump/data --password Test123
Run Code Online (Sandbox Code Playgroud)

感谢你的帮助。

mongodb mongodb-atlas

5
推荐指数
3
解决办法
8983
查看次数

React Native Expo Google Fonts:不是系统字体,尚未通过 Font.loadAsync 加载

我正在使用 Expo Google Fonts 和 useFonts() 方法为我的应用程序导入字体。但是我收到以下错误,但我认为我不需要将 Font.loadasync 与 Google Fonts 一起使用(根据此处的文档)。你能让我知道我在这里做错了什么吗?

import React, { useState } from "react";
import { View, TouchableOpacity, Text, StyleSheet, Platform } from 'react-native'
import { useFonts, Kanit_400Regular, Kanit_500Medium, Kanit_700Bold } from '@expo-google-fonts/kanit';
import Colors from '../constants/Colors'

const Header = props => {

  useFonts({Kanit_400Regular, Kanit_500Medium, Kanit_700Bold})

  return (
    <View style={styles.headerContainer}>
      <View style={styles.logo}>
        <Text style={styles.headerText}>HEADER</Text>
      </View>
      <View>
        <Text style={{...styles.headerText, fontSize: 14 }}>LOGIN</Text>
      </View>
    </View>
  )
} 

const styles = StyleSheet.create({
  headerContainer: {
    padding: 15, …
Run Code Online (Sandbox Code Playgroud)

fonts react-native expo

4
推荐指数
1
解决办法
3856
查看次数

MongoDB 索引:String 与 Int

数据库管理新手。我有一个书籍数据库,我想为 ISBN 创建一个长度为 13 个字符的索引。示例:'9781509825889'

目前我正在使用字符串索引,但我已经阅读了关于是否存储为 int 或字符串以进行索引优化的冲突点。

看起来我有 Int32 或 Int64 选项,我认为上面的 ISBN 对于 Int32 来说太大了,但是否值得切换到 Int64 进行查询优化,还是应该坚持使用字符串?是否有任何显着的性能提升?

谢谢

javascript database indexing mongodb

2
推荐指数
2
解决办法
1980
查看次数