Monday, 3 April 2017

Swap an object in a Mongoose array with another object in the array of another document

Consider this schema:

    let userSchema = new Schema({
    email: { type: String, required: true },
    password: { type: String, required: true },
    books: [{
        owner: String,
        cover: String,
        title: String,
        link: String,
        requestsReceived: { requestingUser: String, bookOffered: String },
        requestsSent: { toUser: String, bookWanted: String },
        beingRequested: { type: Boolean, default: false },
        beingSent: { type: Boolean, default: false }
    }],
    ip: String
});

the books array contains of objects which hold a variety of information. How can I take a certain book object from array of document 1 and swap it with array of document 2 preferably with the least amount of queries to the DB.

I know this is a bit difficult. Much appreciated.



via JohnSnow

No comments:

Post a Comment