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
使用Express、Mongoose在嵌套MongoDB文档中搜索_Mongodb_Express_Search_Mongoose_Nested - Fatal编程技术网

使用Express、Mongoose在嵌套MongoDB文档中搜索

使用Express、Mongoose在嵌套MongoDB文档中搜索,mongodb,express,search,mongoose,nested,Mongodb,Express,Search,Mongoose,Nested,我想搜索由邮递员发送的_idhaving stepPath=url。 下面是嵌套文档结构 [ { "_id": "5ebf028e989a2e2628d9d3f6", "funnelName": "Mortgage Leads1", "group": "Mortgage", "category": "Finance", "funnelStep": [ { "viewsStorage": [

我想搜索由邮递员发送的_idhaving stepPath=url。 下面是嵌套文档结构

[
{
    "_id": "5ebf028e989a2e2628d9d3f6",
    "funnelName": "Mortgage Leads1",
    "group": "Mortgage",
    "category": "Finance",
    "funnelStep": [
        {
            "viewsStorage": [
                {
                    "_id": "5ebf028e989a2e2628d9d3f8",
                    "viewsCounter": {
                        "currentDate": "2000-12-31T18:30:00.000Z",
                        "viewsNo": 0
                    }
                }
            ],
            "_id": "5ebf028e989a2e2628d9d3f7",
            "stepType": "Advertorial",
            "stepName": "Angle Ver 1",
            "stepPath": "google12.com",
            "isTracking": true
        }
    ],
    "__v": 0
},
{
    "_id": "5ec15febb8a83019bc966932",
    "funnelName": "Mortgage Leads",
    "group": "Mortgage",
    "category": "Finance",
    "funnelStep": [
        {
            "viewsStorage": [
                0,
                0
            ],
            "_id": "5ec15febb8a83019bc966933",
            "stepType": "Advertorial",
            "stepName": "Angle Ver 1",
            "stepPath": "google.com",
            "isTracking": false
        },
        {
            "viewsStorage": [
                1,
                0
            ],
            "_id": "5ec15febb8a83019bc966934",
            "stepType": "Optin",
            "stepName": "21 Day Plan",
            "stepPath": "fb.com",
            "isTracking": true
        },
        {
            "viewsStorage": [
                2,
                0
            ],
            "_id": "5ec15febb8a83019bc966935",
            "stepType": "Checkout",
            "stepName": "Checkout Ver 1",
            "stepPath": "google.com",
            "isTracking": true
        }
    ],
    "__v": 0
}]
我使用的结构模型-

const mongoose = require('mongoose')
const funnel = new mongoose.Schema({
funnelName:{
    type:String,
    unique:true
},
group: String,
category: String,
funnelStep: [{
    stepType: String,
    stepName: String,
    stepPath: String,
    isTracking: Boolean,
    viewsStorage: []
}] })
mongoose.model('Funnel',funnel)
邮递员寄来的JSON-

{
"funnelName":"Mortgage",
"url" : "google12.com",
"user_id" : "BATR0001",
"Date": 1 }
[]
邮递员接获回应-

{
"funnelName":"Mortgage",
"url" : "google12.com",
"user_id" : "BATR0001",
"Date": 1 }
[]
获取我正在使用的方法-

router.get('/',function(req,res){
Funnel.find({"Funnel.funnelStep.stepPath":req.body.url},function(err,funnels){
    if(err){
        console.log(err)
    }else{
        console.log(req.body.url)
        console.log(funnels)

        return res.json(funnels) 
    }
}) })
除此之外,我也尝试过跟随-

Funnel.find({stepPath:req.body.url},function(err,funnels){.....}
Funnel.find({stepPath:req.params.url},function(err,funnels){....}
上述操作都不起作用,只返回NULL或空数组


有人能帮我查询一下吗?

find
方法中用
funnelStep.stepPath
替换
funnelStep.stepPath

Funnel.find({ "funnelStep.stepPath": req.body.url }, function (err, funnels) { 

})