monoy suronoy
monoy suronoy

Reputation: 911

Sails query model always returns undefined

I want to get all stream data with thread value but not including null. On my mongodb console it works with $ne but on my query sails model it always returns undefined?

Example query:

Stream.findOne({thread: {$ne: null } }, function(err, st){
            if(err) return err;
            console.log("st", st);
       });

How can I resolve this?

Upvotes: 2

Views: 442

Answers (1)

chridam
chridam

Reputation: 103365

Use the .native() method:

Stream.native(function(err, collection) {
    if (err) return res.serverError(err);
    collection.find({
        "thread": { "$ne": null }
    }).toArray(function(err, st) {
        if (err) return res.serverError(err);
        console.log("st", st);
        return res.ok(st);
    });
 });

Or the .where() method:

var myQuery = Stream.find();
myQuery.where({'thread':{ '$ne': null}});

myQuery.exec(function callBack(err, results){
    console.log(results)
    });

Upvotes: 1

Related Questions