Update record

47 views
Skip to first unread message

Ruslan Matkovsky

unread,
Nov 23, 2015, 7:15:54 AM11/23/15
to Mongoose Node.JS ODM
Hi everyone!
I have one problem with update some records using mongoose.
There is a Scheme in my project
var itemSchema = new Schema({
            item: {type: Number, ref: 'Item'},
            channelID: String,
            isRefunded: Boolean,
            bonus: Boolean
        });

var schema = new Schema({
    _id: Number,
    username:                 { type: String, index: { unique: true, sparse: true } },
    playerData: [
            {
              gameId: Number,
              purchasedItems:       [itemSchema]
            }
    ]
};

UserModel.model = mongoose.model( 'User', schema );

I need to update record below UserModel.model.playerData[].purchasedItems[].channelId and using query of find UserModel.model._id: Number and UserModel.model.playerData.gameId: Number 

How can I do it?

A

unread,
Nov 23, 2015, 5:19:11 PM11/23/15
to Mongoose Node.JS ODM
I personally use underscore; if you want to use that then find the index of each

var a = _.findIndex(UserModel.model,{'_id':model_id})    ;
var b = _.findIndex(UserModel.model[a].playerData,{'gameId':gameid});
console.log(UserModel.model[a].playerData[b].channelID);
Reply all
Reply to author
Forward
0 new messages