How to do find in node and mongodb?

前端 未结 3 728
无人共我
无人共我 2021-01-22 22:25

This is my \'usergroups\' data

{
    \"_id\": {
        \"$oid\": \"58f7537ec422895572e988a1\"
    },
    \"name\": \"aaa\",
    \"groupname\": \"group north,gro         


        
3条回答
  •  感情败类
    2021-01-22 23:09

    You can use the $in operator:

    Usergroup.findOne({
                mobilenumber: 0509867865
            },
            function(err, usergroup) {
                if (err) {
                    return handleError(res, err);
                }
                if (!usergroup) {
                    return res.status(404).send('Not Found');
                }
                console.log(usergroup.groupname);
            //group north ,group south
                Group.find({
                        groupname: { $in: usergroup.groupname.split(",") } 
                    },
                    function(err, group) {
                        if (err) {
                            return handleError(res, err);
                        }
    
                        return res.json(group);
                    });
            });
    

提交回复
热议问题