我在node.js应用程序中使用猫鼬,这是我的配置
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}).then(()=>{
console.log(`connection to database established`)
}).catch(err=>{
console.log(`db error ${err.message}`);
process.exit(-1)
})
Run Code Online (Sandbox Code Playgroud)
但在控制台中它仍然会警告我
DeprecationWarning:不建议使用当前的“服务器发现和监视”引擎,并将在以后的版本中将其删除。要使用新的“服务器发现和监视”引擎,请将选项{useUnifiedTopology:true}传递给MongoClient构造函数。
有什么问题 我以前没有使用过useUnifiedTopology,但是现在它出现在控制台中,我添加了它,但它仍然给我这个错误。为什么?我什至不使用mongoClient。
编辑:
正如Felipe Plets回答的那样,猫鼬存在问题,他们在较晚版本的猫鼬中修复了该错误。因此您可以通过更新猫鼬版本来解决问题
我想做以下事情:当用户上传带有表单字段的文件时,检查表单字段是否为空,如果是,则不上传文件。我正在使用这个代码
fileFilter: (req,file,callback) =>{
if(req.body.name.trim().length < 1){
callback(null, false)
}
}
Run Code Online (Sandbox Code Playgroud)
但它给了我未定义的 req.body.name 并且据我所知 fileFilter 将 Express.Request 作为第一个参数,那么为什么我无法访问正文?
完全错误
类型错误:无法读取未定义的属性“trim”
谢谢!
我正在为 Google Chrome 开发视频下载器扩展程序,这是我的第一个项目(我是第一次制作 Chrome 扩展程序)。据我所知,您应该使用 JavaScript 来实现扩展功能。
我想做以下事情:我在某个有视频播放器的网站上,我想让用户下载该视频。我认为Video Downloader Plus与我的目的有关。那么我怎样才能让用户做上面的功能呢?
我将使用 mongoose (mongo atlas) 部署客户端的 web 应用程序,必须承认,他不是很慷慨,我知道 Sanbox (M0 集群) 不适合生产模式,但想知道为什么?是否有任何原因导致在生产中使用 M0 不安全,我的意思是它的存储适合网站需求提前致谢,这确实是简单的应用程序,具有添加帖子删除帖子和编辑帖子的功能,就像简单的 WordPress 主题一样。提前致谢。
PS:我在此链接中找不到任何真正的问题
我正在阅读 mongoosejs 文档,了解填充方法并使用“ref”填充有点难以理解,我也看到了很多 stackoverflow 问题,MDN,但没有人花太多时间来解释这一点
var personSchema = Schema({
_id: Schema.Types.ObjectId,
name: String,
age: Number,
stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});
var storySchema = Schema({
author: { type: Schema.Types.ObjectId, ref: 'Person' },
title: String,
fans: [{ type: Schema.Types.ObjectId, ref: 'Person' }]
});
var Story = mongoose.model('Story', storySchema);
var Person = mongoose.model('Person', personSchema);
Run Code Online (Sandbox Code Playgroud)
所以这是一个例子,文档说 ref: 引用我们应该使用哪个模型,但在这种情况下,作者有对 person 的引用,它的类型是 objectId 以及它如何存储整个模式(_id,名称,年龄,故事)与故事属性相同,它如何存储整个架构(以猫鼬语言“文档”表示)。
Story.
findOne({ title: 'Casino Royale' }).
populate('author').
exec(function (err, story) {
if (err) return handleError(err);
console.log('The author is %s', …Run Code Online (Sandbox Code Playgroud) 我正在比较两个日期,但问题是,在我的本地计算机生成的日期中,当我使用setHours这样的方法时console.log(new Date(new Date().setHours(8)));,它给我的时区的输出2020-07-22T04:41:46.624Z是 GMT+4(乔治亚标准时间),但在我的 Heroku 服务器(欧盟)或repl.it 上它给出了时区偏移量,-0它为我提供了2020-07-22T08:41:46.624Z完全相同的命令,我该如何解决这个问题?否则,如果我登录new Date()两台机器,即使我向它们添加时间,它们也会记录相同的日期,其设置小时(或分钟等)会改变时区
你好,我是 WebRTC 的新手,我试过这段代码
const yourVideo = document.querySelector("#face_cam_vid");
const theirVideo = document.querySelector("#thevid");
(async () => {
if (!("mediaDevices" in navigator) || !("RTCPeerConnection" in window)) {
alert("Sorry, your browser does not support WebRTC.");
return;
}
const stream = await navigator.mediaDevices.getUserMedia({video: true,
audio: true});
yourVideo.srcObject = stream;
const configuration = {
iceServers: [{urls: "stun:stun.1.google.com:19302"}]
};
const yours = new RTCPeerConnection(configuration);
const theirs = new RTCPeerConnection(configuration);
for (const track of stream.getTracks()) {
yours.addTrack(track, stream);
}
theirs.ontrack = e => theirVideo.srcObject = e.streams[0];
yours.onicecandidate = …Run Code Online (Sandbox Code Playgroud) 我正在创建一对一的webrtc视频聊天室,此代码不起作用,我想知道为什么
function hasUserMedia(){
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
return !!navigator.getUserMedia;
}
function hasRTCPeerConnection() {
window.RTCPeerConnection = window.RTCPeerConnection ||
window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
return !!window.RTCPeerConnection;
}
function startPeerConnection(stream) {
var configuration = {
"iceServers": [{ "url": "stun:stun.1.google.com:19302" }]
};
yourConnection = new RTCPeerConnection(configuration);
theirConnection = new webkitRTCPeerConnection(configuration);
yourConnection.addStream(stream);
theirConnection.onaddstream = function (e) {
theirVideo.src = window.URL.createObjectURL(e.stream);
};
yourConnection.onicecandidate = function (event) {
if (event.candidate){
theirConnection.addIceCandidate(newRTCIceCandidate(event.candidate));
}
};
theirConnection.onicecandidate = function (event) {
if (event.candidate) {
yourConnection.addIceCandidate(new
RTCIceCandidate(event.candidate));
} …Run Code Online (Sandbox Code Playgroud) 我有一个页面,我从服务器获取数据并为受控输入设置状态值。(例如,我有拥有的输入值this.state.name,我从服务器例如戴夫取名字,并将其设置在状态的名称,所以输入的值是戴夫。它的工作原理,但我与对象数组有问题
所以这就是状态
this.state = {
ingredients: [{ ingredient: "", quantity: '' }],
//other properties
}
Run Code Online (Sandbox Code Playgroud)
这就是我如何使用 ingredients
{this.state.ingredients.map(({ ingredient, quantity }, index) => (
<div key={index}>
ingredient: <input value={ingredient} className="ingredientClass" type="text" autoComplete="off" placeholder="e.g: pepper" onChange={{e => this.update(index, "ingredient", e.target.value)} />
quantity: <input value={quantity} autoComplete="off" type="text" placeholder="e.g: 1g" onChange={e => this.update(index, "quantity", e.target.value)} />
<button onClick={this.BtnClick}>delete</button> <br />
{this.state.errorFor === 'ingredientsfield' ? this.state.errmsg : null}
</div>
))}
Run Code Online (Sandbox Code Playgroud)
但这会导致此错误:
警告:组件正在将文本类型的受控输入更改为不受控制。输入元素不应从受控切换到不受控制(反之亦然)。决定在组件的生命周期内使用受控或非受控输入元素。更多信息:
link
为什么会这样?我该如何解决?
PS:我检查并成功从服务器获取成分
更新:onChange 事件的代码
update(index, key, value) {
this.setState(({ …Run Code Online (Sandbox Code Playgroud) 在我的反应应用程序中,我将父母的状态作为道具传递给孩子,如下所示:
<Child parentsState={...this.state} />
Run Code Online (Sandbox Code Playgroud)
它有效。但后来我想为什么不应该在没有扩展语法的情况下通过 this.state ,我确实喜欢:
<Child parentsState={this.state}
Run Code Online (Sandbox Code Playgroud)
它也起作用了。大多数情况下,我使用带有数组的扩展语法,我不知道没有扩展语法的对象和没有它的对象之间有区别吗?
谢谢你!