Q:

Mongoose find and create multidimensional arrays

I'm trying to get the userid, and the array object that contains the specific location within locations.
What I want to accomplish is the following:
The query will return the array location's result.
If not userid exist at all, create it, then return the array of the matching location.
If the location id Number is not there. create a new one,  then return the array of the matching location.
How can I accomplish this?
Current query: 
 easyCrime.findOne({
        userid: userid,
        "locations.location": location
    }, {"locations.$.location": 1}).then(function (err, stats) {

        }

    });

model:
   userid: {
        type: String,
        default: '57c1c0f3b6b20c011242bf22'
    },
    locations: [
        {
            userid: {
                type: String,
                default: '57c1c0f3b6b20c011242bf22'
            },
            location: {
                type: Number,
                default: 1
            },
            easycrime: [
                {
                    optioname : {
                        type: String,
                        default: 'unknown'
                    },
                    chance: {
                        type: Number,
                        default: 500
                    }
                }
            ],
            heavycrime: [
                {
                    optioname : {
                        type: String,
                        default: 'unknown'
                    },
                    chance: {
                        type: Number,
                        default: 500
                    }
                }
            ],

        }
    ],

    timesteal: {
        type:Number,
        default: 0
    }

A:

I presume that easyCrime is Model, cause there is no such thing as findOne query in a Document. If it is a Model please name it EasyCrime.

I had a really hard time interpreting your question. Base on what I understand, this is your solution
EasyCrime
    .findOne({ userid: param.userid})
    .exec((err, crime) => {

        //userid not exists at all, create new
        if (!crime) {
            let newCrime = new EasyCrime({...});
            newCrime.save(...);
            return;
        }

        //Check if location exists
        for (let i = 0; i < crime.locations.length; ++i) {
            if (crime.locations[i].location === param.location) {
                //crime.location[i] is what you're finding
                return;
            }
        }

        //Cannot find any location with provided param.location
        crime.locations.push({
            userid: ...,
            location: param.location,
            ...
        });

        crime.save(...);
    })

