Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有相反结果的Mongodb.find()_Javascript_Mongodb_Routes - Fatal编程技术网

Javascript 具有相反结果的Mongodb.find()

Javascript 具有相反结果的Mongodb.find(),javascript,mongodb,routes,Javascript,Mongodb,Routes,我有这个请求 router.get('/', async (req, res) => { //I connect to the DB and i return the collection with Posts const posts = await loadPostsCollection(); res.send(await posts.find({ "tmima": { "$eq": 'andriko

我有这个请求

router.get('/', async (req, res) => {
        //I connect to the DB and i return the collection with Posts
        const posts = await loadPostsCollection();
        res.send(await posts.find({ "tmima": { "$eq": 'andriko' } }).toArray());
    });
现在一切都很好。。问题是我想动态地找到帖子,而不是在那里找到这个
'andriko'
。。 我尝试了这个
{“tmima”:{“$eq”:req.body.params}
,但它现在可以工作了。。。奇怪的是,使用
req.body.params
它显示了除了那些有
tmima:'andriko'

这个“tmima”值来自动态路由,所以我需要这个
req.body.params
或类似的东西来显示基于路由的帖子

提前谢谢

编辑!!包括正面部分

路由器.js

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/katigories/:tmima",
    name: "katigories",
    props: true,
    component: () => import("../views/katigories.vue"),
    children: [
      { path: 'anakoinoseis', name: 'anakoinoseis', props: true, component: () => import("../views/Ypokatigories/Anakoinoseis.vue")},
      { path: 'roster', name: 'roster', props: true, component: () => import("../views/Ypokatigories/RosterView.vue")},
      { path: 'vathmologia', name: 'vathmologia', props: true, component: () => import("../views/Ypokatigories/Vathmologia.vue")}
    ]
  }
axios.js

import axios from 'axios'

const url = 'http://localhost:5000/api/posts/';

class AnnouncementsService {
  //GET Annaouncements
  static getPosts() {
    return new Promise ((resolve,reject) => {
        axios.get(url).then((res) => {
            const data = res.data;
            resolve(
                data.map(post => ({
                    ...post,
                    createdAt: new Date(post.createdAt)
                }))
            );
        })
        .catch((err)=> {
            reject(err);
        })
        
    });
  }
阿纳科诺赛斯

<script>
import AnnouncementsService from '../../store/axios'

export default {
  name: 'Announcements',
  props: ['tmima'],
  data() {
    return {
      posts: [],
      text: '',
      title: ''
    }
  },
  async created() {
    try {
      this.posts = await AnnouncementsService.getPosts();
      await console.log(this.tmima)
    }catch(err){
      this.error = err.message;
    }
  },
</script>

从“../../store/axios”导入公告服务
导出默认值{
名称:'公告',
道具:['tmima'],
数据(){
返回{
员额:[],
文本:“”,
标题:“”
}
},
异步创建(){
试一试{
this.posts=await announcensservice.getPosts();
wait console.log(this.tmima)
}捕捉(错误){
this.error=err.message;
}
},

const posts=wait loadPostsCollection.find({“tmima”:req.body.params});res.send(posts)
@BlackMath不幸的是它不起作用了……但是你能告诉我如何从前端客户端传递参数吗?@BlackMath参数是通过路由传递的。我的意思是我有道具['tmima']在我的.vue文件中,您可以在router.js文件中看到它是一个孩子。此外,我还添加了一个console.log in created()钩子,它给出了正确的答案…基本上,我的vue得到了正确的值,如果我硬编码corect值,我的DB工作正常。问题是这两者之间会发生什么!!