进行简单的$ match聚合将导致“ Expected“ [”或AggregationStage但找到“ {”。错误。
{
$text: {
$search: "search query"
}
}
Run Code Online (Sandbox Code Playgroud) 继这个问题之后.
我觉得我几乎就在那里,但我对异步的不完全理解阻止了我解决这个问题.我基本上试图使用bcrypt来散列密码并决定分离hashPassword函数,以便我可以在应用程序的其他部分使用它.
hashedPassword 保持返回undefined虽然...
userSchema.pre('save', async function (next) {
let user = this
const password = user.password;
const hashedPassword = await hashPassword(user);
user.password = hashedPassword
next()
})
async function hashPassword (user) {
const password = user.password
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds, function(err, hash) {
if (err) {
return err;
}
return hash
});
return hashedPassword
}
Run Code Online (Sandbox Code Playgroud) 我已经做了很多研究,但我似乎无法完全理解这一点。
我已经构建了一个应用程序。客户端是用 Vue-cli 构建的,port 8080从客户端文件夹运行,服务器从port 8081. 本质上,我有这个:
client
- package.json
- node_modules
- src
- build
- index.html
server
- package.json
- node_modules
- app.js
- auth.js
Run Code Online (Sandbox Code Playgroud)
我不确定如何解析文件夹结构,以便可以将其部署到 Heroku。
根据我所做的大量研究和这个答案(诚然是一篇很老的帖子),一个建议是将两者结合起来,但是我将如何解析每个文件夹(客户端和服务器)中的两个 package.json 文件)?我合并它们吗?
另一个建议是创建两个单独的 Heroku 应用程序。然后我可以将我的axiosbaseURL设置为app_name.herokuapp.com?
两者中的哪一个通常被认为是理想的解决方案?我真的卡在这里了...
我即将开始为应用程序构建一个小的javascript模块.我已经接触过两种组织代码的方式:对象文字和IIFE.我知道,对于IIFE,所有变量和函数都保持私有,除非另有公开,但是还有其他原因我会在对象文字上使用它吗?
为什么我要使用对象文字:
var gojiraSays = 'Toxic Garbage Island!!!'
var app = {
printStuff: function(){
console.log(gojiraSays)
}
}
Run Code Online (Sandbox Code Playgroud)
...说IIFE版本:
var app = (function(){
var gojiraSays = 'Toxic Garbage Island!!!'
var yellGojira = function(){
console.log(gojiraSays);
}
return{
yellGojira: yellGojira
}
}());
app.yellGojira();
Run Code Online (Sandbox Code Playgroud) 假设我们有一个构造函数及其原型:
function Person(name){
this.name = name;
}
Person.prototype = {
setSex: function(sex){
this.sex = sex;
return this;
},
setEyes: function(color){
this.eyes = color;
return this;
},
setHair: function(color){
this.hair = color;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
为了创建一个人并构建他们的特征,我们使用方法链,如下所示:
var person1 = new Person('John');
person1.setEyes('Blue').setHair('Brown').setSex('male')
Run Code Online (Sandbox Code Playgroud)
除了我令人沮丧地使用的框架要求我创建第sex 一个,然后是eyes然后hair(特别是按照这个顺序)。我认为期望方法按顺序排序是愚蠢且不合理的,但我别无选择。因此,我正在尝试构建一个更宽容的函数,并采用(可能无序的)方法列表并在后台按顺序构建它们。
问题是,我什至不知道从哪里开始。
我在考虑的是,在链中的每个方法执行后将结果推送到一个对象中,然后触发一系列遵循预定义顺序的函数(可能看起来像这样):
person1 = {
hair: 'brown',
sex: 'male',
eyes: 'blue',
}
var orderOfMethods = ['sex','eyes','hair'];
orderOfMethods.forEach(function(){
if(currentValue in person1){
//do that function
}
})
Run Code Online (Sandbox Code Playgroud)
但这似乎是一个非常复杂的解决方案。有任何想法吗?
我如何打破液体中的两个循环。到目前为止,我有,这似乎对我不起作用。
{% for x in a %}
{% for y in b %}
{% if y = 2 %}
{% break %}
// When this loop breaks, the parent for loop should also break
{% endif %}
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud) 在实例模式下调用新的 p5 实例时,我需要传递一个附加参数。
我希望能够做到这一点:
var x = 50;
var sketch = function(p5){
p5.setup = function(x){
// Canvas setup etc
rect(x,40,40,40)
}
}
new p5(sketch, x)
Run Code Online (Sandbox Code Playgroud)
现在,它显示为undefined,这让我相信new p5只能接受一个参数。是否有一种方法可以让我向实例传递额外的参数,而无需破解 p5?
我已经vee-validate验证了输入字段.每次输入字段中发生失效错误时,我都希望发出一个事件.
因此,我认为最好只创建一个computed代表该领域的领域$validator.errors.
问题是该$emit事件watch永远不会被解雇.
我的代码是这样的:
<template>
<input
type="number"
name="quantity"
v-validate="{
max_value: 50
}" />
</template>
<script>
export default {
data () {
return {}
},
computed: {
formErrors () {
const errors = this.$validator.errors;
return errors;
},
},
watch: {
formErrors (value) {
return this.$emit('form-errors', value)
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud) 我有这样的文件:
[
{
title: 'apple',
attributes: {
colour: 'red',
kind: 'fruit'
},
{
title: 'broccoli',
attributes: {
colour: 'green',
kind: 'vegetable'
}
},
]
Run Code Online (Sandbox Code Playgroud)
在我的聚合管道中,我想从本质上将层次结构扁平化一层深,如下所示:
[
{
title: 'apple',
colour: 'red',
kind: 'fruit'
},
{
title: 'broccoli',
colour: 'green',
kind: 'vegetable'
}
]
Run Code Online (Sandbox Code Playgroud)
问题是,嵌套对象中的键在文档中是动态的,因此我无法$project静态地使用它们。我需要动态地将这些嵌套的键/值对拉到顶部对象。
刚刚将包添加normalize-scss到我的新 Vue 项目中,但没有应用任何样式......我都尝试过:
@import 'normalize-scss' 在我的 styles.scss
import 'normalize-scss'在我的main.js页面
难道我做错了什么?该包显然存在,因为该应用程序在运行,但它实际上并未应用任何 css 规则。
javascript ×5
mongodb ×2
mongoose ×2
node.js ×2
vue.js ×2
bcrypt ×1
constructor ×1
express ×1
heroku ×1
liquid ×1
p5.js ×1
sass ×1
shopify ×1
vee-validate ×1
vue-cli ×1