Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r is not a function。When attempting to use the search box function through mongoose requests. #86

Open
cxp-13 opened this issue Jan 5, 2024 · 0 comments

Comments

@cxp-13
Copy link

cxp-13 commented Jan 5, 2024

The information about error above:

TypeError: r is not a function
    at E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63257
    at E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\server\lib\trace\tracer.js:133:36
    at NoopContextManager.with (E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\compiled\@opentelemetry\api\index.js:1:7062)     
    at ContextAPI.with (E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\compiled\@opentelemetry\api\index.js:1:518)
    at NoopTracer.startActiveSpan (E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\compiled\@opentelemetry\api\index.js:1:18093) 
    at ProxyTracer.startActiveSpan (E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\compiled\@opentelemetry\api\index.js:1:18854)
    at E:\nextjs_project\promptopia\promptopia\node_modules\next\dist\server\lib\trace\tracer.js:122:103

my api content about search box function:

'use client'
import Prompt from "@models/prompt";
import { connectToDB } from "@utils/database";
import { connect, Document } from "mongoose";
import { useSearchParams } from "next/navigation";
import { NextResponse } from 'next/server'
// 搜索框功能,查询包含searchText的prompt,用户名,tag
export const GET = async (request) => {
    try {
        const searchText = useSearchParams().get("searchText");
        console.log("搜索框 searchText", searchText);

        await connectToDB()

        // 构建查询条件
        const query = {
            $or: [
                { prompt: { $regex: searchText, $options: 'i' } },
                { 'creator.username': { $regex: searchText, $options: 'i' } },
                { tag: { $regex: searchText, $options: 'i' } },
            ],
        };

        // 执行查询
        const results = await Prompt.find(query).exec();
        console.log("搜索框 result", results);
        
        return NextResponse.json(JSON.stringify(results), {
            status: 200
        })

    } catch (error) {
        console.log("搜索框 error", error);
        return new Response(JSON.stringify("Failed to search prompts"), {
            status: 500
        })
    }
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant