Loopback: find, findOne different empty result

Created on 12 Jan 2016  路  5Comments  路  Source: strongloop/loopback

Object.findOne({
where: {
and: [{user_id: user_id}]
}, function(err, object){
console.log(object) // undefined
});
Object.find({
where: {
and: [{user_id: user_id}]
}, function(err, object){
console.log(object) // []
});
findOne = no results returns 'undefined' // This is easy to check for for example ... if(typeof object !== 'undefined'){}
but...
find on no results returns empty array [] or nothing.

blocked triaging

Most helpful comment

I found out why, in the mode definition JSON file ( for me File.json), I needed to add "strictObjectIDCoercion": true to the options array, now querying with any params works

All 5 comments

Hi @evinw,

Could you please provide a sample repo using our loopback-sandbox to reproduce the issue?

Thanks!

@evinw

Do you still have the same issue? If so could you please provide a sample repo to reproduce the issue? Otherwise if it works, please let us know, so we can close this ticket.

Thanks a lot!

Closing this issue due to inactivity; please feel free to comment if you still have the same issue.

Thanks!

@Amir-61 querying the find method with object id returns the object, but when querying with any other params returns an empty array :
File model has : id, imgId and eventId

File.find({where: {eventId: eventId}},function(err,res){
            console.log("found Image " + res)
            cb(err,res);
        })

Any idea why?

I found out why, in the mode definition JSON file ( for me File.json), I needed to add "strictObjectIDCoercion": true to the options array, now querying with any params works

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Overdrivr picture Overdrivr  路  4Comments

ImanMh picture ImanMh  路  4Comments

daankets picture daankets  路  4Comments

crandmck picture crandmck  路  3Comments

bryannaegele picture bryannaegele  路  4Comments