我正在尝试使用mongoose在 MongoDB 中创建一个新对象。
这是我的猫鼬模式:
const UsersSchema = new Schema<BaseUser>(
{
email: {
type: Schema.Types.String,
index: true,
required: true,
unique: true,
},
someKey: {
type: Schema.Types.String,
default: null,
required: false,
enum: Object.values(SomeEnumObj),
}
},
{
timestamps: true,
}
);
enum SomeEnumObj = {
TEST = "TEST",
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下方法创建新用户时:
model.create({
email: 'some@email.com',
}).exec()
Run Code Online (Sandbox Code Playgroud)
抛出以下错误:
users validation failed: someKey: `null` is not a valid enum value for path `someKey`.,
Run Code Online (Sandbox Code Playgroud)
我能够通过设置来解决这个问题:
users validation failed: someKey: `null` is not a valid enum value …Run Code Online (Sandbox Code Playgroud) 所以,我偶然发现了这种奇怪的情况:
我有一个全局 React Context 提供程序,提供全局状态,如下所示
const Context = createContext();
const ContextProvider = ({children}) => {
const [state, setState] = useState('');
return <Context.Provider value={{state, setState}}>{children}</Context.Provider>
}
const useMyState = () => {
const {state, setState} = useContext(Context);
return {
state,
setState
}
}
const Component = () => {
const {setState} = useMyState();
useEffect(() => {
elementRef.addEventListener('click', () => {
setState('someState');
});
return () => {
elementRef.removeEventListener('click', () => null);
}
},[])
return <>
// ...
</>
}
Run Code Online (Sandbox Code Playgroud)
eslint建议setState …
我正在尝试调用Lambda函数并在完成时返回Promise,
但我得到以下错误:
“ createUser(...)。则不是函数”
const createUser = (phone) => {
return lambda.invoke({
FunctionName: 'createUser',
Payload: JSON.stringify({"phone": phone})
}, (err, data) => {
let payload = JSON.parse(data.Payload);
if (payload.statusCode != 200) {
Promise.reject(payload);
}
Promise.resolve(payload);
})
}
createUser('')
.then(res => console.log(res))
.catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)
已经尝试使用以下方式声明新的Promise:
let promise = new Promise((resolve, reject) => {...})
Run Code Online (Sandbox Code Playgroud)
但这也不起作用...
我正在尝试导出 umd 模块 w. webpack,并通过<script>标签使用它。mytsconfig.json配置为导出commonjs文件
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
"declaration": true,
"sourceMap": true
}
}
Run Code Online (Sandbox Code Playgroud)
我的 webpack 配置设置为输出 umd lib,
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
test: './src/index.tsx'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'awesome-typescript-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', …Run Code Online (Sandbox Code Playgroud) 我有这个 Moongoose 模式:
var userSchema = new mongoose.Schema({
firstname: {
type: String,
required: true,
min: 3,
max: 24
},
lastname: {
type: String,
required: true,
min: 3,
max: 24
},
id: {
type: Number,
required: true,
min: 9,
max: 9
},
mediations: [assetSchema]
});
Run Code Online (Sandbox Code Playgroud)
当我尝试添加 ID 为111222333的新用户时,出现下一个验证错误:
{
"errors": {
"id": {
"message": "Path `id` (111222333) is more than maximum allowed value (9).",
"name": "ValidatorError",
"properties": {
"max": 9,
"type": "max",
"message": "Path `{PATH}` ({VALUE}) is more than …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个具有某种用户会议系统的应用程序,最近我们的产品团队要求包括一些预定的推送通知,提醒用户他们在 30 分钟前、10 分钟前和 10 分钟后有会议会议。(我们使用 FCM 作为推送通知服务)
目前,对于每个新会议,我们都会在 AWS CloudWatch Events 规则上注册一个 cron 作业,但我开始意识到,由于预期有大量注册会议,这可能不是实现它的最佳方式......(例如,如果我们将有 100 个活动会议,我们将有 300 个注册的 CloudWatch Events 规则...
所以我的问题是有更好的方法来实现这样的服务吗?
编辑:客户端都是 IOS(Swift) 和 Anrdoid(Java)
push-notification amazon-web-services amazon-cloudwatch firebase firebase-cloud-messaging
node.js ×3
javascript ×2
mongodb ×2
mongoose ×2
typescript ×2
aws-lambda ×1
closures ×1
enums ×1
firebase ×1
react-hooks ×1
reactjs ×1
webpack ×1