I am trying to get a user id and an array object that contains a specific location in places.
I want to do the following:
The query will return the result of placing the array.
If the user ID does not exist, create one and then return an array of the appropriate location.
If the location identifier is missing. create a new one, then return an array of the appropriate location.
How can i do this?
Current request:
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 }
maria
source share