【发布时间】:2021-08-21 21:57:44
【问题描述】:
大家好,我有关于 mongodB atlas 的数据,这是我的 mongoose Schema mongoose Schema 这是客户 client
import React, { useState, useEffect } from 'react';
import { Container, AppBar, Typography, Grow, Grid } from '@material-ui/core';
import { useDispatch } from 'react-redux';
import SearchBar from "material-ui-search-bar";
import Posts from './components/Posts/Posts';
import Form from './components/Form/Form';
import { getPosts } from './actions/posts';
import useStyles from './styles';
import memories from './images/memories.png';
const App = () => {
const [currentId, setCurrentId] = useState(0);
const dispatch = useDispatch();
const classes = useStyles();
useEffect(() => {
dispatch(getPosts());
}, [currentId, dispatch]);
return (
<Container maxWidth="lg" >
<AppBar className={classes.appBar} position="static" color="inherit">
<Typography className={classes.heading} variant="h2" align="center">Search Bar</Typography>
<SearchBar />
</AppBar>
<Grow in>
<Container>
<Grid container justify="space-between" alignItems="stretch" spacing={3}>
<Grid item xs={12} sm={7}>
<Posts setCurrentId={setCurrentId} />
</Grid>
<Grid item xs={12} sm={4} >
<Form currentId={currentId} setCurrentId={setCurrentId} />
</Grid>
</Grid>
</Container>
</Grow>
</Container>
);
};
export default App;
使用这个https://github.com/TeamWertarbyte/material-ui-search-bar
搜索我尝试使用“猫鼬模糊搜索插件” 我这样做Mongoose Fuzzy Searching
import mongoose from 'mongoose';
import mongoose_fuzzy_searching from 'mongoose-fuzzy-searching';
const postSchema = mongoose.Schema({
title: String,
message: String,
creator: String,
tags: [String],
selectedFile: String,
link:String,
createdAt: {
type: Date,
default: new Date(),
},
})
postSchema.plugin(mongoose_fuzzy_searching, { fields: ['message', 'title'] });
var PostMessage = mongoose.model('PostMessage', postSchema);
export default PostMessage;
【问题讨论】:
-
堆栈溢出 (SO) 允许在帖子中嵌入代码。与其提供代码图片的链接,不如直接将实际代码粘贴到帖子中,这样想要帮助的人就不必重新输入示例代码来进行测试。
-
谢谢老哥搞定了
标签: node.js mongodb express mongoose