These are chat archives for Automattic/mongoose

21st
Feb 2017
Ankur sharma
@ankur1163
Feb 21 2017 07:51
can someone help me out in mongoose ?

@ankur1163
I need help
this is my mongodb entry

{
    "_id": {
        "$oid": "58aacdb301a0e206f542999d"
    },
    "username": "ankur",
    "__v": 0,
    "selectedbooks": [],
    "requestsrecieved": [],
    "requestssent": [
        "2",
        {
            "requesterusername": "ankur",
            "thumbnail": "http://books.google.com/books/content?id=5IPN9_MgzmcC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
            "title": "Paradise",
            "isbn": "9781407065243",
            "username": "megha"
        }
    ],
    "approved": [],
    "count": 20,
    "mybooks": [
        {
            "description": "To make the journey into the Now we will need to leave our analytical mind and its false created self, the ego, behind. From the very first page of Eckhart Tolle's extraordinary book, we move rapidly into a significantly higher altitude where we breathe a lighter air. We become connected to the indestructible essence of our Being, \u201cThe eternal, ever present One Life beyond the myriad forms of life that are subject to birth and death.\u201d Although the journey is challenging, Eckhart Tolle uses simple language and an easy question and answer format to guide us. A word of mouth phenomenon since its first publication, The Power of Now is one of those rare books with the power to create an experience in readers, one that can radically change their lives for the better.",
            "title": "The Power of Now",
            "thumbnail": "http://books.google.com/books/content?id=sQYqRCIhFAMC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
            "isbn": "9781577313113"
        },
        {
            "description": "It's no wonder that The Power of Now has sold over 2 million copies worldwide and has been translated into over 30 foreign languages. Much more than simple principles and platitudes, the book takes readers on an inspiring spiritual journey to find their true and deepest self and reach the ultimate in personal growth and spirituality: the discovery of truth and light.",
            "title": "The Power of Now",
            "thumbnail": "http://books.google.com/books/content?id=2gICvgAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api",
            "isbn": "9781536956825"
        }
    ]
}

i want to remove

{
            "requesterusername": "ankur",
            "thumbnail": "http://books.google.com/books/content?id=5IPN9_MgzmcC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
            "title": "Paradise",
            "isbn": "9781407065243",
            "username": "megha"
        }

which is inside requestsent
I have isbn , username values

Ankur sharma
@ankur1163
Feb 21 2017 07:59
   delsrequest: function(obj, callback) {
        console.log("object in deslrequest",obj)
        var rusername=obj.rusername;
        var ty = {"username.requestssent":rusername}
        var isbn = obj.isbn;
         Books.where({ "username":rusername}).find("requestssent").find({"isbn":isbn}).remove({}, function(err, resp){
                    if (err) {
                        callback(err, null);
                        return;
                    }
                    else{
                        console.log("got something",resp)
                        callback(err, resp);
                    }


        });


    },
this query doesnt look right
Paul "Joey" Clark
@joeytwiddle
Feb 21 2017 08:35
This message was deleted
Hari Adhikari
@harryac07
Feb 21 2017 12:10

Hello,
I have got problem using passport authentication. I have got a error that I couldnot findout what it says. it occured during the passport authentication using local-passport. The strange part is, it only occured sometimes. Rest of the time, login is successful.

My code is :

passport.use('local',new LocalStrategy({
    usernameField: 'email'
},
function(username, password, done) {
    console.log('username in line 17 passport  : '+username);
    // Upto here, it gives email as a username successfully
    User.findOne({
        email: username
    }).exec(function(err, user) {
        console.log(user); // prints undefined and gives error
        if (err) {
            // gives error here
            return done(err);
        }
        if (!user) {
            return done(null, false, {
                "message": "Incorrect Username."
            });
        }
        if (!user.validPassword(password)) {
            return done(null, false, {
                "message": "Incorrect Password." + password
            });
        }
        console.log(user);
        return done(null, user);

    });
}
));

But it works fine until and unless I started sending message in my clientside inside input field. I have used jQuery keyPress event with e.which=13. If I trigger this event I failed logging in using passport and following errors appear.

TypeError: schematype.castForQuery is not a function
at cast (/Users/Harry/Desktop/socketio/node_modules/mongoose/lib/cast.js:229:32)
at Query.cast (/Users/Harry/Desktop/socketio/node_modules/mongoose/lib/query.js:2753:12)
at Query.findOne (/Users/Harry/Desktop/socketio/node_modules/mongoose/lib/query.js:1353:10)
at /Users/Harry/Desktop/socketio/node_modules/mongoose/lib/query.js:2310:21
at new Promise.ES6 (/Users/Harry/Desktop/socketio/node_modules/mongoose/lib/promise.js:45:3)
at Query.exec (/Users/Harry/Desktop/socketio/node_modules/mongoose/lib/query.js:2304:17)
at Strategy._verify (/Users/Harry/Desktop/socketio/app_api/config/passport.js:20:6)
at Strategy.authenticate (/Users/Harry/Desktop/socketio/node_modules/passport-local/lib/strategy.js:90:12)
at attempt (/Users/Harry/Desktop/socketio/node_modules/passport/lib/middleware/authenticate.js:348:16)
at authenticate (/Users/Harry/Desktop/socketio/node_modules/passport/lib/middleware/authenticate.js:349:7)
at module.exports.login (/Users/Harry/Desktop/socketio/app_api/controllers/authentication.js:303:4)
at Layer.handle [as handle_request] (/Users/Harry/Desktop/socketio/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/Harry/Desktop/socketio/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Users/Harry/Desktop/socketio/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/Harry/Desktop/socketio/node_modules/express/lib/router/layer.js:95:5)
at /Users/Harry/Desktop/socketio/node_modules/express/lib/router/index.js:277:22