question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Find multiple model objects by ids

See original GitHub issue

Hey Team,

Is there a way to find multiple model objects by ids?

await HotelModel.find({ id: { $in: ids } });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chenducommented, May 29, 2021

After digging into the code, this way works for me.

const { rows } = await XxxModel.find({
      $in: {
        search_expr: 'id',
        target_expr: ids
      }
    });
    return rows;
1reaction
rajasekar-mucommented, May 28, 2021

@AV25242 above options not working me too also, please check.

@chendu can you try below query builder option,

const select_param = [{ $field: ‘id,name,status’ }]; let params = {where: {_type:‘hotel’,$in: { search_expr: ‘id’, target_expr: [ids-array] }} } let raw_query = new Query(params, bucketName).select(select_param).build(); let Hotels = await ottomanConnection.query(raw_query);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django get objects for many IDs - Stack Overflow
My current solution works, however it hammers the database with a a bunch of get queries inside a loop.
Read more >
Making queries | Django documentation
Once you've created your data models, Django automatically gives you a database-abstraction API that lets you create, retrieve, update and delete objects.
Read more >
Is it possible to do a multiple id request? - Google Groups
I'm working with backbone and backbone-relational and it would be nice if I could retrieve multiple models at once. I've read the docs...
Read more >
Active Record Query Interface - Ruby on Rails Guides
The find method will raise an ActiveRecord::RecordNotFound exception if no matching record is found. You can also use this method to query for...
Read more >
What's the most performant way to get multiple documents by ...
What's the most performant way to get multiple documents by an indexed field? ... (But with real object IDs and a whole lot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found